This is a fairly simple notice for people already familiar with the uses of the Winsock control.
Trick #1 - The BIND Method
For some reason, it wasn't until recently that I discovered exactly what the Bind method can do. Previously I thought it was only good for binding UDP sockets to a port.
I was wrong. This is the answer to my prayers. Various programs give you the option of listening on any local IP. 0.0.0.0 is for ANY port of course. Or you may select 127.0.0.1 if you only want to accept local connections. And of course, if you have more than one IP, you can listen on any of them as well.
While this is fairly obvious in the Winsock API, until now, I thought it was outside the Winsock Control's capabilities.
Want to create a TCP listening session on 127.0.0.1? Do the following:
Winsock.Bind 10000, "127.0.0.1"
Trick #2 - UDP Broadcast
This one isn't as obvious as the other one, but just as easy. First, let me paint an example of its use.
Problem: You have a multiplayer network-enabled game, and you want to have the convenience of the game giving you a listing of all available hosted games on the network.
Solution: UDP Broadcasting! Set each host to bind a UDP socket to a single port - let's say 4500.
Host.Bind 4500, "0.0.0.0"
Ok, now the Client has to somehow get that hosts address. Do this:
Client.RemoteHost = "255.255.255.255"
Client.RemotePort = 4500
That well send "PING" to every computer on the network targeted at port 4500! Now, the host is expecting a request like this, so it sends a response:
Host.RemoteHost = Host.RemoteHostIP
Now the client will recieve a PONG from every host on the network - and it may list each host for the user to connect to via TCP after whatever means of negotiation you want.
If you don't know how to use the Winsock Control, and would like to know, ask me to send you an example of it's use.