|
-
Sep 12th, 2002, 01:13 PM
#1
winsock question
as i embark on my chat program... i have a winsock question..
i know how most examples use port 1001 or whatever.. but what if the port is used.... as in what if I set the server portion to listen at port 1001 but the client already has a program using that port.. so when my app tries it won't be able to... shoudl the server have a control array of winsocks? whats the best way to go about making sure it can use a valid port and handling the multiple incoming connections..
-
Sep 12th, 2002, 02:46 PM
#2
Frenzied Member
As of the latest update, port 1001 (which falls in the well known port numbers range of 0-1023) is unassigned. However, you should probably use a port number in the registered ports range of 1024-49151. This range is "listed by the IANA and on most systems can be used by ordinary user processes or programs executed by ordinary users.".
Having passed along that tidbit, I would say that you should be safe if you select an unregistered port that is reasonably high in the registered range. Client apps that let the system select the port for them will most likely be assigned a port number well below 9999. That leaves quite a range of port numbers for use by any client apps running on the server's system.
IMHO, your server shouldn't need an array of listeners.
-
Sep 12th, 2002, 02:48 PM
#3
Originally posted by ccoder
As of the latest update, port 1001 (which falls in the well known port numbers range of 0-1023) is unassigned. However, you should probably use a port number in the registered ports range of 1024-49151. This range is "listed by the IANA and on most systems can be used by ordinary user processes or programs executed by ordinary users.".
Having passed along that tidbit, I would say that you should be safe if you select an unregistered port that is reasonably high in the registered range. Client apps that let the system select the port for them will most likely be assigned a port number well below 9999. That leaves quite a range of port numbers for use by any client apps running on the server's system.
IMHO, your server shouldn't need an array of listeners.
so bascially... if the port that my server uses is in use on the client system i shoudl tell the client that the port is in use and they need to close whatever program is using it if they want to run my app right?
-
Sep 12th, 2002, 03:39 PM
#4
Hyperactive Member
Yep...
The server sould not have to care about these things, that's the clients problem.
I myself would use a port like 7653 or something... Very high and very randomly chosen...
"Experience is something you don't get until just after you need it."
-
Sep 12th, 2002, 04:04 PM
#5
Frenzied Member
Originally posted by kleinma
so bascially... if the port that my server uses is in use on the client system i shoudl tell the client that the port is in use and they need to close whatever program is using it if they want to run my app right?
Ummm, no!
The server doesn't care if the port it is listening on, on the system that it is running on, is in use by another app on another system. Follow that?
You only need to be concerned if some other app on the server's system has already grabbed the port that the server wants to listen on when it (the server) starts up.
-
Sep 12th, 2002, 05:45 PM
#6
Originally posted by ccoder
Ummm, no!
The server doesn't care if the port it is listening on, on the system that it is running on, is in use by another app on another system. Follow that?
You only need to be concerned if some other app on the server's system has already grabbed the port that the server wants to listen on when it (the server) starts up.
i know the server won't care... but the client app will care.. right?
-
Sep 12th, 2002, 06:31 PM
#7
Frenzied Member
If a port on the client is already assigned this is not server's problem...The port server is listening on has nothing to do with client's port...if using TCP. the client port is important only if you have to send data back to the client.(in chat program you normally have to).
The easiest way is to create Winsock Control and make it listen on a port say 1001....
and another Winsock Control Array.. whenever there's a request load an element to this array and use it to accept the request...
-
Sep 12th, 2002, 08:09 PM
#8
Frenzied Member
Originally posted by kleinma
i know the server won't care... but the client app will care.. right?
All the client has to be concerned with is setting its remote port number to the port that the server is listening on.
As long as the client sets its local port to zero (or even omits the statement from its code) the system will assign an available port for the client to use (locally). Then, once the connection is established, both sides can send as much data back and forth as is necessary. The server is not concerned with the port number that was assigned to the client - TCP/IP takes care of delivering data to the correct addresses.
I think you are trying to do more than you really have to - things that the system does for you. Go to this thread Winsock troubles and download the example app that I uploaded. It has 3 client forms and a server form. As each client connects & disconnects, the assigned port numbers are displayed (along with a lot of other info about what is going on). Perhaps this will help you see what we are trying to say.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|