Solved

python UDP how do I specify an IP destination?

Posted on 2014-02-26
3
468 Views
Last Modified: 2014-02-28
Hi,

In my UDP, python, server client system, an RTS, how does my client specify the IP address location of the server? - with a HELO type message in a byte array
What does the client send region look like? and the server receive loop?
Do game servers first have a client-join loop and THEN a gameplay loop, or one loop for everything?

Thanks
0
Comment
Question by:beavoid
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
gelonida earned 500 total points
ID: 39891353
For the first part of your question:
What exactly do you try to achieve?

when a client sends a UDP message you specify destination host and port in the sendto command.
sent = sock.sendto(data, address)

Open in new window


when you receive a message you get the data and the address the message is coming from,
for example:

data, address = sock.recvfrom(2048)

Open in new window


Or do you want to send another address in the payload of a message?

Concerning the 2nd part of your question:

I have no experience with game servers. Perhaps somebody else can help out
0
 

Author Comment

by:beavoid
ID: 39894907
Thanks

I think that is good. I have datagrams sending and receiving.
But, on the receiver end, how do I pick apart the data?



In
data, addr = s.recvfrom(1024)

is data the exact byte array I send from the client? How do I parse the individual bytes?
I usually have data[0] byte as the message type code
and the subsequent bytes, the relevant data for the message.

?
0
 
LVL 16

Assisted Solution

by:gelonida
gelonida earned 500 total points
ID: 39895029
you should receive exactly the same byte string.


It might be fragmented though if I recall correctly or to datagrams might be  concatenated.

Thus normally you have a receive buffer. if the data is not sufficient to be parsed you read more before parsing. If you have more data than needed to be parsed. you parse what can be parsed and keep the rest for later parsing.

I don't know how your package is built up, but potentially

struct.unpack might help to extract data from your byte string.

You can go tot http://docs.python.org/2.7/library/struct.html , select your
python version and check.

Without knowing the exact data structure it's a little difficult to help. thus only a generic link with the command, that should be able to get your job done
0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question