Quick Question
Working on a small instant messaging client / server situation to get myself aquainted with Winsock...I just have a quick question.
Here''s the scenario: The Client connects to the server via Port 8888 which the server is listening on. The client sends some packet of data to the server. The server examines the packet of data and decides which thread will execute the command and starts processing it. At this point, there are other clients in line waiting to be served on port 8888. Do I have to physically disconnect the socket from the first client before the next clients send request will generate a FD_ACCEPT message or once the packet is finished being sent a new FD_ACCEPT message is generated? Can more than one client be "connected" to port 8888 and just send data whenever needed? I hope this wasn''t too confusing. If anyone needs further explaining let me know.
Thanks in advance!
Mikehttp://cs.wpunj.edu/~bowersom
When you call accept() on the original listening socket, it will return a new socket that you can perform all communication with the client with. The original listening socket will be able to generate new FD_ACCEPT messages without needing to be disconnected. In fact calling close() on the original socket might cause you to drop pending connect requests.
Can more than one client be "connected" to port 8888 and just send data whenever needed?
TCP - The socket at port 8888 is a listening socket. Each connection, once accepted, moves to another, exclusive, OS-determined, port.
UDP - Yes. Use recvfrom(). It''ll tell you where the data comes from.
TCP - The socket at port 8888 is a listening socket. Each connection, once accepted, moves to another, exclusive, OS-determined, port.
UDP - Yes. Use recvfrom(). It''ll tell you where the data comes from.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
I don''t believe that the OS will "move the connection to another port." It will move it to another socket, true, but it won''t move it to another port. If it did, firewall rules and network masquerading wouldn''t work.
You may be confusing it with the behavior on the client side, where the OS (usually) chooses an arbitrary port number for the outgoing connection as it''s set up.
The receiving end uses the quadlet of to identify connections. That''s why you can''t have more than one *outgoing* TCP connection on the same port; this guarantees uniqueness of the quadlet. (Using more than one dstip on the same machine means the machine is multi-homed, which is very common for firewalls for example)
You may be confusing it with the behavior on the client side, where the OS (usually) chooses an arbitrary port number for the outgoing connection as it''s set up.
The receiving end uses the quadlet of
enum Bool { True, False, FileNotFound };
So once a client connects, another socket is dynamically declared to take of sending and receiving data back and forth. Do I manually keep track of these sockets, or will the application know when it received a FD_READ on a certain socket and accept the data from it? Do I keep track of these with a list? Sorry for so many questions.
Thanks again!
Thanks again!
Mikehttp://cs.wpunj.edu/~bowersom
quote:
Original post by hplus0603
You may be confusing it with the behavior on the client side, where the OS (usually) chooses an arbitrary port number for the outgoing connection as it''s set up.
Probably, yes.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
In order for the system to send you FD_READ on the sockets returned from accept(), you''d have to call WSAAsyncSelect() on the returned socket.
(And Fruny, when was the last time you got a FD_ACCEPT message on a UDP socket?)
(And Fruny, when was the last time you got a FD_ACCEPT message on a UDP socket?)
quote:
Original post by SiCrane
And Fruny, when was the last time you got a FD_ACCEPT message on a UDP socket?
About the same time I last got one on a TCP socket: I don''t use the winsock API.
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement