troubleshooting Question

c++ recv() problem

Avatar of OutlawZ
OutlawZ asked on
Programming Languages-OtherC++Editors IDEs
22 Comments1 Solution1321 ViewsLast Modified:
I have a recv function inside of a thread so that i can constantly receive messages and still be able to control my GUI.
The receiving part however isn't really working the way i was hoping. Cause at a point the strings that i receive are broken appart.
So like if im expecting the string: hello_world, i get ("hel", llo", "_worl", "d") chopped up in sepperate strings.

Now my idea is to receive the messages and wait untill it encounters the newline \r\n which indicates the end of a string. When it doesn't see a newline (\r\n) yet it should paste the received string to the other strings it received before so that i still end up with the correct string.

I hope i explained it good enough of about what im trying to do, if not then please say so and ill try it again.

Would something like this work? (pseudo code)
for(;;)
{
while(recv(socket, buffer, strlen(buffer), 0))
{
    if(!strstr(buffer,"\r\n"))
    {
        completeBuffer += buffer;
    }
}
}
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 22 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 22 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros