Search code examples
delphisocketsnetwork-programmingdelphi-7winsock

How to look for any and all computers on a network which are using my service?


I have a custom pair of client/server sockets (TJDServerSocket and TJDClientSocket) which wrap the TServerSocket and TClientSocket in the ScktComp unit. I don't have any issues to fix, but would like to know something. I'd like to add a feature to the client side to automatically search the network for any instances of a server socket (specifically my server component).

I'm open to any suggestions, but has to be specific to the use of the ScktComp unit in Delphi 7.

Here's a link to the components of mine.


Solution

  • Never used the TServerSocket and TClientSocket myself, and I don't have the help files within reach, so I can't immediately see if this would work with those components. For a project I did I needed something like that too. I ended up with using UDP to broadcast a discovery request (within the same subnet of course). The server, listening on a particular port for such a request, would reply its data back. When multiple servers would exist (a situation that though rare could occur) the client just picked the server with the required service(s) and the least load. That load was part of the data the server send back. It worked out nice, wasn't all that difficult to write, and turned out reasonably efficient too.

    The request protocol is completely up to you. The one I devised allowed clients to send a request detailing the services they need, and servers replying listing their services and the load (= connected clients in active use). After selecting the server to talk to, a client would register itself for the services it needed, and could use them after that.

    Hope this helps.