Developing UDP netcode on one machine?

Started by
15 comments, last by oliii 14 years, 9 months ago
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.
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.
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.

Everything is better with Metal.


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.
You might want to look at the Etwork samples for how to send/receive UDP packets on the same machine.
enum Bool { True, False, FileNotFound };


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!
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.
enum Bool { True, False, FileNotFound };


Personal preference to avoid debuggers :)
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.
-=[Megahertz]=-


'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 ?

This topic is closed to new replies.

Advertisement