Socket, strange behaviour of recv

Hello, this is my first socket program (class actually).

Here's my bit of code:

1
2
3
4
5
6
7
	char buf[128];
	int bt;
	while(b.good())
	{
		buf[bt = b.recv(buf, 128)] = 0; // Append null char
		cout  << bt << ": " << buf;
	} 


here's is ClientSocket::recv:
1
2
3
4
5
6
7
8
9
10
11
int ClientSocket::send(const char *buf, int len, int flags)//int flags = 0
{
	if(!can_send()) // Checks for some internal flags
		return -1;

	int bytes_s = ::send(main_socket, buf, len, flags);
	if(bytes_s < 0) 
		error_flags[5] = true;

	return bytes_s;
}


The output for a run of that loop looks like this:

Imagine "hello" was send (no null byte)
5: hello :2

I don't understand why does the ":2" appear and it does in every loop run.

I believe the problem is not with the sending part as I've tested with putty (raw mode) and a simple client wrote by me.

I appreciate if you can give me some lights to what's happening.

Thanks,
Hugo Ribeira

EDIT: I found out that the ":2" because my loop is running twice but where come the 2 read bytes and where do they go since they don't appear in output?

Could they be the enter key? ("\r\n")

If they are why are they being sent separatly?
Last edited on
Never mind, it was indeed putty sending the ENTER key signal over the network, wrote a client of mine again and the error disappeared.
Topic archived. No new replies allowed.