• Advertisement
Sign in to follow this  

Developing UDP netcode on one machine?

This topic is 3130 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I tried running my project on one machine, two instances of it. One instance I host a game, the other I connect to it. Both instances are communicating over the same port, would that cause packets to get mixed up and confused between the instances ? EG: some client->server packets end up going back to the client, and viceversa ? There wasn't anything about this in the FAQ. Thanks for help.

Share this post


Link to post
Share on other sites
Advertisement
Usually, clients don't use a specific port - instead they pick a random port number and initiate contact with the server. Use 0 as a port and the underlying network API will pick a random port for you.

Share this post


Link to post
Share on other sites
use a specific port for the host, and a arbitrary / unspecified port for the client and bob's your uncle. put 0 in, the system will pick a port for you.

Share this post


Link to post
Share on other sites

Hey, thanks guys, that fixed a few things, but apparently I'm still not processing / generating my packets properly as the remote client quits when I start sending packets containing position/velocity data. The hunt continues.

Share this post


Link to post
Share on other sites


I got it all working.. I found what was making it quit out:


if(flags & UP_ORIGIN)
{
e->realorigin.x = *(float *)&data[pos]; pos+=4;
e->realorigin.y = *(float *)&data[pos]; pos+=4;
e->realorigin.z = *(float *)&data[pos]; pos+=4;
}


I forgot the & infront of data... so much for sleep-deprived coding!

Share this post


Link to post
Share on other sites
Is there a reason why your debugger didn't simply stop at the bad pointer dereference and show you the source of the segfault?
If so, you should figure out what that is. With any crash, you should immediately be told what line is crashing, and why, or your development won't ever be efficient.

Share this post


Link to post
Share on other sites
Quote:
Original post by radioteeth


Personal preference to avoid debuggers :)


Hope you don't plan on trying to get a job in the software development industry.

Share this post


Link to post
Share on other sites


'Personal' != 'Work'

I actually write firmware for work, and using a debugger for that is absolutely essential as devices I am working tend to only have LED lights.. But on a computer I usually just logprint stuff..

Thanks again guys.. I am having a problem with the server suddenly receiving tons of garbage data packets from nowhere when a client disconnects. This happens inconsistently, so sometimes it works fine, but I think it has something to do with handling a late packet that arrives after a client disconnects.. hrmm..

What specific situation would cause a recvfrom to be loaded full of huge nothingness packets from nowhere ?

Share this post


Link to post
Share on other sites
Quote:
Original post by radioteeth
Personal preference to avoid debuggers :)
So rather than use a debugger and spotting the problem straight away, you prefer to spend ~6 hours (9:30am - 3:30pm) with log-print debugging?

Quote:
Original post by radioteeth
Thanks again guys.. I am having a problem with the server suddenly receiving tons of garbage data packets from nowhere when a client disconnects. This happens inconsistently, so sometimes it works fine, but I think it has something to do with handling a late packet that arrives after a client disconnects.. hrmm..

What specific situation would cause a recvfrom to be loaded full of huge nothingness packets from nowhere ?
Nothing, the packet would have to be coming from somewhere.

Also, there's no such thing as "disconnect" in UDP (since there's no such thing as a "connection"). You must be sending the server something to notify that a client is disconnecting. I would suspect it's around there somewhere.

Share this post


Link to post
Share on other sites

Codeka: Pretty hasty assumption that between posts my whole life revolved around solving that one problem, don't you think? ADHD makes life unpredictable!

Although I've become rather proficient debugging with logprint, maybe I should use the debugger.. They just feel icky. Personally, with something like the & infront of the variable, I think the compiler should check those things too. But what I think isn't the solution.... meh.



Good news:

I figured out that the way I handled the retval from recvfrom was causing these 64k phantom packets... there was *no packet* actually coming in..

recvfrom was returning SOCKET_ERROR (-1) and I was storing it in an unsigned short (65535), and because I wasn't checking for the SOCKET_ERROR (assuming that a zero was error code) my code thought it had received a 64k packet..

The error code is 10054, which says "On a UDP-datagram socket this error indicates a previous send operation resulted in an ICMP Port Unreachable message."

..which naturally occurs as a result of the client sending off his disconnect notification and then closing the socket when the server is trying to send a game update.

simple..


Thanks again guys.

Share this post


Link to post
Share on other sites
Quote:
They just feel icky.


If you're using GDB, I would agree.

Personally, I think MSVC is the killer app for Windows. It's so superior, it's not even a competition.

Although Eclipse isn't bad in general (too bad it has to sit on top of GCC for C/C++)

Share this post


Link to post
Share on other sites
Yeah when I think debugger, I think of the one in MSVC. It's awesome.

I've never used GDB and i hope i never have to, if i do do any dev on linux then yeah i pretty much log print debug.

Share this post


Link to post
Share on other sites
Quote:
Original post by hplus0603
Quote:
They just feel icky.
If you're using GDB, I would agree.
Meh - get a decent IDE or GUI front-end (XCode isn't half bad for this purpose). *Any* debugger is hell to work with in text-mode.

Share this post


Link to post
Share on other sites



I'll scope out Xcode..

I'd probably be using MSVC if I weren't currently limited to an acer netbook as my development platform (ahhhh!) as it comes with a solid-state 8gig harddrive and I don't even have space to download express versions of MSVC, let alone install them. I've heard many good things about Visual Assist.

Share this post


Link to post
Share on other sites
Visual Studio is pretty awesome, especially on the debugging side. It's well worth thinking about it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement