Solved

python UDP how do I specify an IP destination?

Posted on 2014-02-26
3
476 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 17

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 17

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ElasticSearch Filter Query 1 286
Python Install On Mac Yosemite 8 199
hasOne  challenge 59 171
Python Encoding Problem \u2013 4 143
Installing Python 2.7.3 version on Windows operating system For installing Python first we need to download Python's latest version from URL" www.python.org " You can also get information on Python scripting language from the above mentioned we…
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
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 if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

710 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