Sign in to follow this  
CTEagle

Winsock - identifying sender - RESOLVED

Recommended Posts

I have a chat server application that allows multiple clients to connect to it. I can send messages from the server to all clients and from any of the clients to the server. Now I want to be able to identify which client has sent a message. The following code is how my server displays messages from the clients:
case FD_READ:
{
     for (int i = 0; i <= (g_intNumOfClients); ++i)
     {
          recv(g_sockClient[i],recvbuffer,256,0);			
     }

     AddText(hHReceive,"\r\n");
     AddText(hHReceive,recvbuffer);				
}


What I want to be able to do is retrieve the value of "i" only when a message is received, not every pass through "for". Any thoughts? Thanks in advance. [Edited by - CTEagle on June 8, 2007 12:24:40 PM]

Share this post


Link to post
Share on other sites
Thanks for the reply incin. I will read over the information at that link. I was able to identify and display out who the sender was by using the following:


for (int i = 0; i <= (g_intNumOfClients-1); ++i)
{
int iResult = recv(g_sockClient[i], recvbuffer, 256, 0);

if ( iResult > 0 )
{
AddText(hHReceive,"\r\n");
AddInteger(hHReceive,i);
AddText(hHReceive,"->");
AddText(hHReceive,recvbuffer);
}

Share this post


Link to post
Share on other sites
also check out:

http://msdn2.microsoft.com/en-us/library/ms740120.aspx

this will fill in a "sockaddr" structure, giving the IP address of the sender.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this