Hey all.

Can some please confirm some winsock items, I am starting to doubt my self about it now.

The question is this:
If you created a client server program, what port does the client winsock.localport actually connect? Is it the same port that you request it connect to, or is it different?

Can someone please create a simple client server program to either test wheather I'm going insane or not?

Recommended Answers

All 3 Replies

Hi bushman_222 :)

I've just ran my server/client app which I'm working on and then did a netstat -a at the command prompt to check the ports that are being used...

TCP jcxp:1448 localhost:49551 ESTABLISHED
TCP jcxp:49551 localhost:1448 ESTABLISHED

jcxp is my machine name, so it appears that the client uses port 1448 and the server uses 49551 (which I set it to use).

I closed the app and re-opened it and the ports have changed slightly...

TCP jcxp:1457 localhost:49551 ESTABLISHED
TCP jcxp:49551 localhost:1457 ESTABLISHED

So it appears the client will use any port, but as it is the one initiating the connection with the server, then I presume the server will reply to the client port that it contacts the server through.

Hope that helps.

That is great, thank you. That eliminates that possibly,

Thanks again jonifen

That is great, thank you. That eliminates that possibly,

Thanks again jonifen

No problem, glad I could help.

One more thing though, I tried connecting from 2 different computers at the same time to the same server application which was on a 3rd computer. One worked, the other sat there waiting, didn't time out or anything. If I disconnected the first computer, the 2nd would auto connect after a pause of a second or so.

Definitely seems that its one connection per port, so if you're hoping to use a client and management tool at the same time, you may have to add another winsock control to the server application (unless there is a guru who knows a way around it :))

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.