Filling up networkbuffer?

Hello

I have a problem, which I think is because my network buffer gets filled up. The return from the socket are often wrong, extra characters, lines have dissapeared or swapped place. See quote below, I will make some comments which expains.

This is a typical output that is right:

BEGIN_STATE 12
YOU 0
THUNDERSTORM 565.2897 424.2897 17.78225 17.78225 847.2651
THUNDERSTORM 796 488 0 0 1000
RAINCLOUD 286.3252 403.6786 11.03226 2.21768 529
RAINCLOUD 362.534 683.5198 1.270017 15.333 552
RAINCLOUD 176.7596 459.3835 3.940578 14.39226 52
RAINCLOUD 679.2167 468.4387 3.491115 17.74968 128
RAINCLOUD 224.4912 253.3117 17.7931 15.16077 3
RAINCLOUD 865.8184 103.2683 8.128882 14.29691 78
RAINCLOUD 472.6571 202.8026 11.30711 19.70681 158
RAINCLOUD 66.68775 74.06797 7.19282 0.05627193 395
RAINCLOUD 893.2477 141.7175 4.344702 4.733662 5
RAINCLOUD 440.331 209.3724 0.2740121 1.964139 21
RAINCLOUD 529.2446 388.2446 -12.68456 -12.68456 0
RAINCLOUD 526.4629 385.4629 -11.21367 -11.21367 96.72792
RAINCLOUD 532.2457 391.2457 -9.818912 -9.818912 0
RAINCLOUD 532.8381 391.8381 -8.362541 -8.362541 0
RAINCLOUD 532.9994 391.9994 -6.891953 -6.891953 0
RAINCLOUD 533.8867 392.8867 -5.418518 -5.418518 0
RAINCLOUD 534.9225 393.9225 -3.936247 -3.936247 0
RAINCLOUD 535.0871 394.0871 -2.434725 -2.434725 0
RAINCLOUD 536.3301 395.3302 -0.9332234 -0.9332234 12.72792
RAINCLOUD 537.9113 396.9113 0.5758972 0.5758972 12.72792
RAINCLOUD 538.0795 397.0795 2.110391 2.110391 12.72792
RAINCLOUD 539.8742 398.8742 3.640115 3.640115 12.72792
END_STATE

ALl lines are stopped with /n, just so you now that. Often there comes some RAINCLOUD lines before BEGIN_STATE, or the whole thing looks corrupted. I will post more examples later.
Here are some related code:
1
2
3
4
5
6
7
8
9
10
11
#define DEFAULT_BUFLEN 2048
	char recvbuf[DEFAULT_BUFLEN];
	int recvbuflen = DEFAULT_BUFLEN;
	char *recvbufPnt ;
	recvbufPnt = recvbuf;
	int result;
	cloud me;//For holding where in the return of GET_STATE our thunderstorm are located.
	this->write("GET_STATE\n");
	result = recv(this->ConnectSocket, recvbuf, recvbuflen, 0);
	//Who am I?
	printf(recvbuf);

If you need more code you can find it in my other thread, [url=http://www.cplusplus.com/forum/windows/41339/]here[/url]

Making the buffer bigger often makes the application crash more often and faster, so I am not really big it should be.
I also guess that Google could help me a bit, and I will try. It is just that this should be finished within midnight, so I am kind of desperate. I know that I wont finish it, but I will do my best :)

Thanks :)

Edit: I was thinking, there might be possible to read from the socket more than one time to see if it's empty or not. I have also set the buffer size to 8292, and I think it should be ok, but I have to do some more tests first.
Last edited on
printf takes a C string and I doubt the data received is null-terminated.
Use cout.write(recvbuf,result);

Check return values.
Don't use #define for constants.
Topic archived. No new replies allowed.