Results 1 to 10 of 10

Thread: Server Socket-Client Socket error...have no clue ..help!

  1. #1

    Server Socket-Client Socket error...have no clue ..help!

    When I try to send text from my server to the client but not in an onconnect or onrecieve event, but from a button click even when they are connected, it gives this message and fails to send it.

    But when it is in an onconnect or onrecieve event it sends the message and with no trouble.

    Could someone please help me?

    Socket not connected or address not supplied.

    procedure THXDSK.Button1Click(Sender: TObject);
    begin
    HDSSOCK1.Socket.SendText('Test 2');
    end;

    Thank you.
    Nicholas.
    <br />
    <br />Please join: http://holzstukka.proboards81.com

  2. #2

    Server Socket-Client Socket error...have no clue ..help!

    Hello Voltrox!

    A TCP Server can handle multiple connections at the same time. Therefore the serversocket (your HDSSOCk1.Socket) only listen for new incoming connections (at your specified port number). If a new connection is made, a new socket is created by the server's listening socket.

    In your app, you try to send data over this listening socket, which is not possible, because the listener do not know, where to send data. If you send some data in the OnConnect or OnReceive event, the correct socket for this connection is passed as parameter.

    The available connection-sockets are stored in the list HDSSOCK1.Socket.Connections. There is an entry for each connection.
    To send some data to each connection do:

    Code:
    procedure THCSDK.Button1Click&#40;Sender &#58; TObject&#41;;
    var i &#58; integer;
    begin
      for i &#58;= 0 to HDSSOCK1.Socket.Connections.Count - 1 do
         HDSSOCK1.Socket.Connections&#91;i&#93;.SendText&#40;'Test 2'+#13&#41;;
    end;
    Keep in mind, that you may have some "dead" sockets in the Socket.Connections list, beceause of connection losts. TCP is not trivial for beginners. For simple task I prefere UDP, I only use TCP for bigger data transfers like database or file transfers.

    HTH

  3. #3

    Server Socket-Client Socket error...have no clue ..help!

    Thank you.

    That was very helpful...

    But...How do I know which socket each client is connected to? is there an easy way to identify it?

    I see the UDP socket components in Delphi 2006, but I have no idea how to use them, could you help me?

    I heard that UDP has error problems and some drawbacks, how can I avoid these?

    Thank you very much.
    Nicholas.
    <br />
    <br />Please join: http://holzstukka.proboards81.com

  4. #4

    Server Socket-Client Socket error...have no clue ..help!

    You are wellcome!

    Each TCP connection is identified by the server IP and Port and client IP and Port (you have this information available at the servers and client side). But I do not think that this information has any purpose for you. Do you need to differentiate between the clients (from the server's view) or are all clients identical?

    Do the server need to send information to some clients without a request form the client? If that is true, you should use threaded TCP connections (which can be an advanced topic).

    Give me a list of features you server has to serve, and I can give you some advice how to implement it.

    Do you mean the Indy components (starts with Tid*)?

    UDP is packet oriented (TCP is connection oriented) but a successful data transfer is not guaranteed by the protocol. You won't get any error message if a UDP package is lost or can not be transmitted. With an TCP connection the transfer is guaranteed by the protocol layer and TCP have built in retransmit. There it has a lot more overhead than UDP.

    UDP is usefull for short messages, for request/response communications between server and client or for regular status updates from an machine. But UDP can not handle multiple connections (because there is no connection).

    It is difficult to explain for me because english is not my mother tongue.

  5. #5

    Server Socket-Client Socket error...have no clue ..help!

    Yes, I need to be able to differentiate between the clients.

    Yes, I need it to send information without requests.

    No, not the Indy (but I would really like to learn how to use Indy, how would I? I don't see any tutorials), i'm using TServersocket.

    It's ok, what is your first language?
    Nicholas.
    <br />
    <br />Please join: http://holzstukka.proboards81.com

  6. #6

    Server Socket-Client Socket error...have no clue ..help!

    Demos for Indy 9 or 10 are available for download on:
    http://www.indyproject.org/Sockets/Demos/index.de.aspx

    HTH

  7. #7

    Server Socket-Client Socket error...have no clue ..help!

    I tried the demo there (only one is there ) and it is for SSL only, and it also had problems and wouldn't compile.
    Nicholas.
    <br />
    <br />Please join: http://holzstukka.proboards81.com

  8. #8

    Server Socket-Client Socket error...have no clue ..help!

    i only use TServerSocket and TClientSocket with no problem.

    To send to one specific client, you can store its socket.

    f.eks:

    Client[ThisClient].Socket:= Socket;

    That way you can enter this later on:
    CLient[AClient].Socket.SendText('hello!');

  9. #9

    Server Socket-Client Socket error...have no clue ..help!

    http://www.atozed.com/indy/demos/10/index.de.aspx

    The "Zip Code Server (OnExecute)" and the "Intro TCP Client" are good introductions.

    You can connect to the server with "telnet localhost 6000". It is a text-based multi-threaded server.

  10. #10

    Server Socket-Client Socket error...have no clue ..help!

    Diaboli, I don't fully understand...Could you explain it in a simpler way?

    thanks...
    Nicholas.
    <br />
    <br />Please join: http://holzstukka.proboards81.com

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •