Read data recived from a socket, how to?

Hello guys i've created my server using sockets in vc++
This is a part of code:
1
2
3
4
5
6
7
8
9
10
11
12
iResult = recv(AcceptSocket, recvbuf, recvbuflen, 0);
		
		if (iResult > 0) {
			printf("[7]Bytes received: %d\n", iResult);
			
			// Echo the buffer back to the sender
			iSendResult = send(AcceptSocket,recvbuf, iResult, 0);
			if (iSendResult == SOCKET_ERROR) {
				printf("[E7]send failed: %d\n", WSAGetLastError());
				closesocket(AcceptSocket);
				WSACleanup();
				


if i printf(recvbuf); it makes a mess on the screen
So how can i print recived data on the screen?
Last edited on
closed account (48bpfSEw)
What sort of data did you send/received? A string or a block with binary data?

I would use a tool which sniffs the tcp/ip traffics to find out what really is going on during transmission.

https://technet.microsoft.com/de-de/sysinternals/bb795532.aspx
1: You are not checking for errors in recv.

You do this by checking if iResult < 0 (if it is 0, then the connection was closed by the remote partner (client or server)).

2: You don't need two separate variables for error checking.

3: Like Necip said, it all depends on the data you are sending or receiving. What are you trying to receive?

4: I had a similar problem with garbage. See this: http://www.cplusplus.com/forum/windows/193815/

I hope this helps you solve your problem.

PS: Please format your question more clearly the next time.
Last edited on
Topic archived. No new replies allowed.