C/C++ VCC programmer here. I think winsock should prevent me from doing the below in a 2nd running instance of my uDP server application, but maybe I'm forgetting something. basically, I create a socket...

Of course I make sure the result is != INVALID_SOCKET;

Now although it isn't mandatory, I'm on a multi homed machine, so I specifically bind the socket to the IP I want to use, and a specific port I want to listen on. So...

struct sockaddr_in sock_adr;
char szMyIP[20] = { "" }; // Just for example.
unsigned short port_num = 12001;      // ditto

sock_adr.sin_family = AF_INET;  
sock_adr.sin_addr.S_un.S_addr = inet_addr(szMyIP );  
sock_adr.sin_port = htons( port_num); // port to listen on
before I bind, I do a sock option to allow broadcast messages on UDP, because I need to do that sometimes.

BOOL bSockOpt = true;   
setsockopt(*pSock0, SOL_SOCKET, SO_BROADCAST, (char *)(&bSockOpt), sizeof(BOOL));
And then i do the bind...

if (bind(*pSock, (struct sockaddr *)(&sock_adr), sizeof(struct sockaddr_in)) == SOCKET_ERROR)
       errStat = WSAGetLastError();
       // ... take evassive action
OK... now I understand that UDP is a connectionless interface. But it seems to me that if I specifically bind to a specific local IP and non zero port number, a second instance of the application should fail that bind and return a socket error when I try. It doesn't make sense for the system to allow two identically "named" sockets (meaning the same type, home IP, and IP port). When I did something similar in JAVA (using JAVA nio), a second app would fail unless I specified '0' for the port number, to let sockets choose its own unused port.

This is not so good. Amazingly both identical sockets in the two app instances work fine, which will confuse my UDP client apps. ("hey... why are you trying to request operation 'x', when YOU just requested that operation?").

I guess I could find a way to see if the my application is already running and either block a second instance or warn that certain operations will be blocked. But isn't there a way I could inquire of winsock before I bind my socket, to see inf there are any others already bound to the same IP and port, and block it myself?