C Board  

Go Back   C Board > General Programming Boards > Networking/Device Communication

Reply
 
LinkBack Thread Tools Display Modes
Old 09-17-2007, 12:06 PM   #1
ex-SPEEDCUBER
 
Join Date: Dec 2005
Location: Canada
Posts: 265
recving gibberish...

I posted this question on GameDev, the threads been going on for 20 posts or so and I still couldn't get it fixed...

It's my first time using async sockets
I'm writing a game and I'm trying to make it send a message whenever the opponent moves
I hardcoded it to send "mma" for debugging purposes and I'm recving the "mma"'s but once in a while, I get these strings of random(ish) chars within the "mma" string

Screen shot
the top right window is the data I'm recving
I put a putchar('\n'); after each recv call

I'm outputing the data right after I recv it so I know it's got nothing to do with not processing it properly
It seems to have something to do with the recvbuffer's size

What happens if the data received is larger than your buffer?
Does recv stop recving once it encounters a \0?

[edit]I just counted the chars, I get the D-" every 255th char and the recvbuffer is an array of 256 chars[/edit]
__________________
Please let me know if there's any part of my code I can change for optimization


OS: Windows XP and Ubuntu
IDE: wxDev-C++ and CodeBlocks
Compiler: GNU GCC

Last edited by h_howee; 09-17-2007 at 12:11 PM.
h_howee is offline   Reply With Quote
Old 09-17-2007, 12:18 PM   #2
Sweet
 
Join Date: Aug 2002
Location: Tucson, Arizona
Posts: 1,698
What does your recv code look like?
prog-bman is offline   Reply With Quote
Old 09-17-2007, 12:27 PM   #3
ex-SPEEDCUBER
 
Join Date: Dec 2005
Location: Canada
Posts: 265
Code:
    char temprecv[256] = {0};
    int BytesSent;

        case FD_READ:
        {
            if (recv(wParam, temprecv, sizeof(temprecv), 0) == 0)
            {
                std::cout<<"You opponent has left the game."<<std::endl;
                PostQuitMessage(0);
            }
            std::cout<<temprecv<<std::endl;
            std::string a(temprecv);
            for (int i = 0; i < a.size(); i++)
            {
                RecvBuffer.push_back(a[i]);
            }
            this->ProcessRecv();
            break;
        }
__________________
Please let me know if there's any part of my code I can change for optimization


OS: Windows XP and Ubuntu
IDE: wxDev-C++ and CodeBlocks
Compiler: GNU GCC
h_howee is offline   Reply With Quote
Old 09-17-2007, 12:48 PM   #4
ex-SPEEDCUBER
 
Join Date: Dec 2005
Location: Canada
Posts: 265
damnit, I always find the solution right after i post here...

Code:
        case FD_READ:
        {
            BytesSent = recv(wParam, temprecv, sizeof(temprecv), 0);
            if (BytesSent == 0)
            {
                std::cout<<"You opponent has left the game."<<std::endl;
                PostQuitMessage(0);
            }
            for (int i = 0; i < BytesSent; i++)
            {
                RecvBuffer.push_back(temprecv[i]);
            }
            this->ProcessRecv();
            break;
        }
__________________
Please let me know if there's any part of my code I can change for optimization


OS: Windows XP and Ubuntu
IDE: wxDev-C++ and CodeBlocks
Compiler: GNU GCC
h_howee is offline   Reply With Quote
Old 09-17-2007, 12:59 PM   #5
Sweet
 
Join Date: Aug 2002
Location: Tucson, Arizona
Posts: 1,698
Yep. Thats what I though the problem was also.
prog-bman is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using inFile to read from TXT yields gibberish Zzaacchh C++ Programming 4 08-05-2008 07:59 PM
How to avoid gibberish? duffmckagan C Programming 8 06-24-2006 10:53 AM
Why is it gibberish? ober General Discussions 11 11-10-2005 01:24 PM


All times are GMT -6. The time now is 05:41 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22