ur_unholyness
March 17th, 2005, 11:52 AM
Can a server program connect to two clients at the same port and exchange different data depending on the client?
|
Click to See Complete Forum and Search --> : Can a server connect to two clients on the same port? ur_unholyness March 17th, 2005, 11:52 AM Can a server program connect to two clients at the same port and exchange different data depending on the client? barrensoul March 17th, 2005, 12:57 PM I believe this is where multithreading comes in handy. ahoodin March 17th, 2005, 01:24 PM Technically, this should not really happen. You have to look at the life cycle of a socket on a socket server. 1. binds the server to a socket. (ip and port.) 2. set that socket to listen with listen. 3. accept an incoming connection. Accept returns a new socket for communication each time. While the server socket is on a particular port and so on, the communications actually occurs on a seperate socket that is returned by accept. This also happens to be the socket that is already connected to the client socket. While yes the server address is the same for both clients, there are actually 2 sockets involved on the server. So while it is said that we are connecting to this server at this IP on this particular port, there is a little shuffle that is occurring to allow 2 clients to use the same server on the *same port*. HTH, ahoodin PS dont forget to rate. Oh yeah, and a server accepts a connection, it really doesn't connect to a client. a client connect()s to a server. barrensoul March 17th, 2005, 02:30 PM Oh yeah, and a server accepts a connection, it really doesn't connect to a client. a client connect()s to a server. This is why we have servre and client not just one thing which could have been called a "user" :D so... what is a socket? I can't realy figure this one out. MrViggy March 17th, 2005, 02:56 PM A "socket" (http://www.webopedia.com/TERM/s/socket.html) is kinda like a channel on the machine. One machine can be used to serve many different applciations. Sockets are a way to allow that to happen. One analogy I like is that of an apartment building. The aparment building has one postal address, but many mailboxes. Sockets are like the mailboxes. If I want to send a message to the apartment manager, then I send it to his mailbox. On the other hand, if I also want to send a message to my friend who lives in the same building, then I send my message to a different mailbox. Viggy ur_unholyness March 18th, 2005, 12:21 PM Well I never expected such a response, but I am glad. So lemme brief yall with the actual problem. I have an application which tracks the motion of a moving body and tries to display it path graphically. Its the client that recieves the co-ordinates from a server and using these co-ordinates, it plots a pixel in the location corresponding to those co-ordinates (of course, after proper handling of the mapping system is done). The reason I need to have two clients connect to the same server is that I need to have one client to just keep track of the identity every new body detected, and the other client is used to do the plotting. The first client just accepts the Body Id and adds to a database, while the other clients uses this Id to request the server to continuously send co-ordinates for plotting. The main goal is to have a single server, the same port thing can be ignored. codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |