Winsock question
-
Hi! I am trying to create a chat application using the async socket mode ( I dont need more than 20 connections at a time so I didnt use overlapped mode). My chat program has a server and clients connected to it. The server returns to all clients the messages sent by a client and all the clients view the same message. The problem is that my chat server can resend a message which came from a client to only one client... I think I made a mistake in the FD_ACCEPT message:
case FD_ACCEPT: { sockaddr_in remoteAddr; int iRemoteAddrLen; iRemoteAddrLen = sizeof(remoteAddr); hRemoteSocket = accept(hSocket, (sockaddr*)&remoteAddr, &iRemoteAddrLen); } break;
This code accepts all incoming clients but only lets me communicate with just one :wtf:! How can I communicate with more clients :confused:?(Do I have to create a new socket for all new clients? :omg: ) Thank you very much for your future answers! :sigh: Well... I am a beginner ... -
Hi! I am trying to create a chat application using the async socket mode ( I dont need more than 20 connections at a time so I didnt use overlapped mode). My chat program has a server and clients connected to it. The server returns to all clients the messages sent by a client and all the clients view the same message. The problem is that my chat server can resend a message which came from a client to only one client... I think I made a mistake in the FD_ACCEPT message:
case FD_ACCEPT: { sockaddr_in remoteAddr; int iRemoteAddrLen; iRemoteAddrLen = sizeof(remoteAddr); hRemoteSocket = accept(hSocket, (sockaddr*)&remoteAddr, &iRemoteAddrLen); } break;
This code accepts all incoming clients but only lets me communicate with just one :wtf:! How can I communicate with more clients :confused:?(Do I have to create a new socket for all new clients? :omg: ) Thank you very much for your future answers! :sigh: Well... I am a beginner ...You may have to keep a reference to all the client sockets that is connected to your server sockets. You can use an array / list of socket descriptors for this. "A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."
-
Hi! I am trying to create a chat application using the async socket mode ( I dont need more than 20 connections at a time so I didnt use overlapped mode). My chat program has a server and clients connected to it. The server returns to all clients the messages sent by a client and all the clients view the same message. The problem is that my chat server can resend a message which came from a client to only one client... I think I made a mistake in the FD_ACCEPT message:
case FD_ACCEPT: { sockaddr_in remoteAddr; int iRemoteAddrLen; iRemoteAddrLen = sizeof(remoteAddr); hRemoteSocket = accept(hSocket, (sockaddr*)&remoteAddr, &iRemoteAddrLen); } break;
This code accepts all incoming clients but only lets me communicate with just one :wtf:! How can I communicate with more clients :confused:?(Do I have to create a new socket for all new clients? :omg: ) Thank you very much for your future answers! :sigh: Well... I am a beginner ...Scolinks wrote: How can I communicate with more clients ?(Do I have to create a new socket for all new clients? ) Indeed you do. The socket you initially create on your server is just used to accept new connections from clients. When you call accept it will return a socket which you use to communicate with that client. You'll need to keep track of all sockets created by th accept fn. Phil
-
Scolinks wrote: How can I communicate with more clients ?(Do I have to create a new socket for all new clients? ) Indeed you do. The socket you initially create on your server is just used to accept new connections from clients. When you call accept it will return a socket which you use to communicate with that client. You'll need to keep track of all sockets created by th accept fn. Phil