🔒 Locked
Client/Server Client/Client Connection
Advertisement
Original Post
Hi, i'm working on a 3D Chat (WINSOCK and C++) and i need to know some suggest about a Public Chat and a Private Chat. For Example: In public chat i can send all message to server and the server send this messages to all client connected. And there i've no problem. The problem is when i try to connect two client for a private chat. In a private chat the messages don't will go to the server, but the messages are sended directly to another client. So i've implemented a thread for a "little server" into the client. But i've some problem with the port. I need to know where i can learn something about this tecnique. Thanks a lot. And sorry for my bad english!
Quote:
Original post by Imgelling
You could just have a flag in the packet (if its private) and only send that message to the correct person instead of broadcasting it to everyone else.
Edit: All of which would pass through the server.
Yes ok, that's work fine. But i need a peer to peer connection to send data like WebCam Streaming or Audio streaming. So i can't use the server to send this data type.
I've another problem: When i try so send multiple message to all client connected to my Server, i lost some messages. I use a structure like this:
for(itl = m_SClient.begin(); itl != m_SClient.end(); ++itl) { iStat = send(sRecSocket, msg.c_str() , msg.size()+1, 0); cout<<iStat<<"\n"; }
Quote:
Original post by Tano_ITA
How can i fix it? Any suggest? thanks a lot.
Sending too much data very fast may lead to lost of data and or choked the target recipient, whatever protocol or blocking scheme you use, a scheduler for controlling the frequency of sending messages is one solution, say send your message on every 64 milliseconds.
Quote:
Original post by Tano_ITA
TCP, blocking. With a thread for every clients.
You shouldn't be losing data with this method. TCP cannot drop parts of data, and if it does and fails to recover the connection is terminated and you would get an error. And blocking send/recv solves the network buffer issues.
So the only remaining options are that you're either receiving errors but ignoring them, or that you're reconstructing the stream incorrectly. What does recv look like for clients?
Quote:
Original post by Tano_ITA
I've another problem: When i try so send multiple message to all client connected to my Server, i lost some messages. I use a structure like this:for(itl = m_SClient.begin(); itl != m_SClient.end(); ++itl) { iStat = send(sRecSocket, msg.c_str() , msg.size()+1, 0); cout<<iStat<<"\n"; }
The reason for that is because you need to process the result of send() and code accordingly to the result. Just for starters, add this conditional statement to see if you have a problem that I'm thinking you are:
for(itl = m_SClient.begin(); itl != m_SClient.end(); ++itl){ iStat = send(sRecSocket, msg.c_str() , msg.size()+1, 0); if(iStat == -1 || iStat != msg.size() + 1) { cout << "Send was not able to deliver all of the data to the specific client.\n"; }}If you get any of those messages, your are flooding the client faster than it can handle so you will need to rewrite your logic, or possibly check the client code as Antheus mentioned.Remember that with TCP, the server can send more data to the client than the client can actually handle (as Core2Duo said), so send will return a value of how many byte were actually sent. If this number is smaller than the entire message you wanted to send, then you can "lose" data since you do not resend it. The data that you send over TCP is never lost in transmission barring a disconnect, but it is possible to "leak" data from your application in this manner.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement