1
votes

I have a basic indy TCP server and a client in which the client sends messages to the server. In the OnConnect event on the server, the clients IP is added to a list box. I would like to get this list box on the client as well with the list box updating as clients connect and disconnect. I am new to the Indy components and unsure what is the best way to do this?

1
Use UDP broadcast, Luke!OnTheFly
@user539484 That is really nice tradition to post message like "To solve the problem use <something>" Luke! :) It is not sarcasm in any way, but it is good practice when we are do not give answer like "copy & paste" instead of "learn this". BTW UDP protocol have one big problem: it is not assuming that is packet reached another client. So it must be realized by HTTP, FTP (or any other more safe protocol) In my previous comment second link is explain how to do this.Abelisto
Perhaps you'll look into already made chat programs, like IntranetChat clone (dreamchat.sf.net) or IRC clients(www.visualirc.net). Well, the latter should be way to complex, but iChat might be nice starting point.Arioch 'The
UDP broadcast would only work in most simple non-structured networks, and actually then you don't need server at all. If you rely on server - then you should ask server for listing clients and routing the messages.Arioch 'The

1 Answers

1
votes

TCP sockets work in both directions - a TCP server can initiate data transfer to the client on the same socket which the client used to connect to the server.

So to push the list of active connections to the client, the IdTCPServer simply iterates all connections and uses the Connection.IOHandler.WriteXXX methods to send the information. There is no technical difference between broadcasting the connection list data and broadcasting a new chat message to all clients.

The only requirement is that the data needs a "message type indicator" (one or more header bytes) which indicate the message type, optionally followed by the message body length and the data.