Hi all, I have a server program which starts up on any one of the 10 ports from 13337 to 13346.

I just opened a socket with this:
Code:
// create the socket
socket = ::socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
if (socket == INVALID_SOCKET)
throw 1;

// bind to the local address
sockaddr_in address;
address.sin_family = AF_INET;
address.sin_addr.s_addr = inet_addr("127.0.0.1");
address.sin_port = 0; // choose any
if (bind( socket, (sockaddr *)&address, sizeof(address) )) {
        ...
and then I used a for-loop to try each of those ports:
Code:
for (int port = remoteFirstPossiblePort; port < remoteLastPossiblePort; port++) {
    cout << "broadcasting!" << endl;
    struct Hello {
        int blarg;
    };

    Hello hello = { 1337 };

    sockaddr_in dest;
    dest.sin_family = AF_INET;
    dest.sin_addr.s_addr = inet_addr(remoteIPAddress);
    dest.sin_port = htons(port);
    int ret = sendto( socket, (const char *)&hello, sizeof(hello), 0, (sockaddr *)&dest, sizeof(dest) );
    if (ret != sizeof(Hello)) {
        throw 1;
    }
}
But it seems, when sendto sends a packet to a remote port that's not opened, any subsequent recvfrom calls return the error WSAECONNRESET.

So two questions:

1. Am I going about this the right way? I'm using one socket to try for different remote ports, is that what I should do here?

2. If I am on the right track, I need to figure out a way to disable this error for this socket. Any ideas?

Thanks!