Skip to main content
gamedev.net
🔒 Locked

Client/Server Client/Client Connection

Started by Tano_ITA Nov 28, 2008 at 5:05 AM 12 replies 2.3k views
Original Post
Tano_ITA
Tano_ITA
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!
Imgelling
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.
my blog contains ramblings and what I am up to programming wise.
Tano_ITA
Tano_ITA
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.
Tano_ITA
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";	}
Escarab
Escarab
If it is UDP is normal to drop some packets once in a while.
Escarab
Escarab
And... if you send it like this, in a for loop, and you are using udp, you probalby is using more bandwith than you have avaliable, it causes more packets to be drop than the usual.
Tano_ITA
Tano_ITA
How can i fix it? Any suggest? thanks a lot.
Antheus
Antheus
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:


TCP or UDP? Blocking or non-blocking?

Tano_ITA
Tano_ITA
TCP, blocking. With a thread for every clients.
Core2Duo
Core2Duo
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.

Antheus
Antheus
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?
Drew_Benton
Drew_Benton
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.
Tano_ITA
Tano_ITA
Ok thanks a lot i will try soon. I've just fixed sending a single string to mi socket. I think a for cicle is a wrong to send multiple message to a client. Now i will try to use your solution. I hope this topic can help some newbie just like me ;).

Thanks a lot!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.