Client/Server message exchange...

I am currently doing the client-server (socket) connection in MFC and faced the problem in data exchanging. When client sends a message, a server receives only one time. How to loop it? Please help. Should server wait coming message at all time?

Algorithm:
Server is waiting (listen) always clients request.
When client connects, server creates a thread.
Then data exchanging.


int bytesRecv = SOCKET_ERROR;
char recvbuf[400] = "";
while(bytesRecv == SOCKET_ERROR)
{
int len = 1024;
bytesRecv = recv(recvSocket, recvbuf, len, 0);
if (bytesRecv == 0 || bytesRecv == WSAECONNRESET)
break;
if (bytesRecv < 0)
break;
}

this function should be in loop?
After the server listens, it needs to call accept. This returns a different socket that communicates with the client...

You need to read up on socket client/server programming before you can use it.
http://lmgtfy.com/?q=tcp+socket+tutorial
Topic archived. No new replies allowed.