Hi... Unless you are using an existing known protocol, in which case you'd idealy use one of the recognised existing port numbers.... Port 80, 8008, 8080 for an HTTP server for example.
Letting the system pick a random port to listen on as a server is a bit unproductive, as how would you inform any likely clients (not on the same machine) what server port to connect to?... Best I think to pick a specific port number to start with for the server to create and listen on, and then let the clients pick a unused port for them to talk with, to "connect" to your server that is listnening on a known port. (UDP is a "connectionless" protocol of course) It is posible to use the same port number to talk and listen on, but not generaly on the same physical machine for both a client and server, something has to be different between them, either the IP address, or port number (or both) Or, the system hasn't a clue as to who what where etc... I guess you could define another localhost address, 127.0.0.2 for example perhaps? AFIK there is no reason why a single machine can't have multiple "local loopback" addresses. Unless someone else knows different. Then you could use the same "Port" number for both client and server, with care... Check out... http://www.iana.org/assignments/port-numbers For typical known port numbers, some may be of use, many are worth avoiding! (to keep script kiddies away, and to avoid strange connect requests)... Note, that ports in the range of... 49152 through 65535 are avaialable for "Private or Dynamic" port assignments. You can use any of them for anything, and being way up there in "High Port Land" should be well out of the way of any malicious port scanners looking for something to play with.... Hope something helps.. Cheers. Dave B. > -----Original Message----- > From: Dod [mailto:[EMAIL PROTECTED] > Sent: Thursday, March 06, 2008 2:48 PM > To: ICS support mailing > Subject: [twsocket] Problem using same UDP port for both > listen and send > > Hello, > > I am working on something like : > > - Create Server UDP socket port 0 - Winsock select the > listening port itself > > - I retrieve port number using GetSockName/.sin_port > > - The Socket server is now listening > > - I create a Socket client to connect to other machine > but I set LocalPort with same socket number as the one > retrieved by server socket > > - I .Connect the client to other machine and .Send the data > > All works fine on XP but the final program must run on NT4 > and if I do this I get WSAEADDRINUSE ( 10048 ) Address already in use. > > If i set LocalPort to 0 before .Connect then all is fine of course. > > Any idea why NT4 cannot not set localport for UDP sending > with same number as port used by a server socket ? May be an > old NT4 Winsock limitation ? > > I know NT4 is old but I have to work on a very old server > that can't be upgraded. May be some of you remember such limitation ? > > Regards. > > > This mail has been scanned by Palmer Cook Computer Services Limited. www.palmercook.co.uk -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be