Solved

python UDP how do I specify an IP destination?

Posted on 2014-02-26
3
454 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Flask is a microframework for Python based on Werkzeug and Jinja 2. This requires you to have a good understanding of Python 2.7. Lets install Flask! To install Flask you can use a python repository for libraries tool called pip. Download this f…
Dictionaries contain key:value pairs. Which means a collection of tuples with an attribute name and an assigned value to it. The semicolon present in between each key and values and attribute with values are delimited with a comma.  In python we can…
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 while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now