Solved

python UDP how do I specify an IP destination?

Posted on 2014-02-26
3
472 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Sequence is something that used to store data in it in very simple words. Let us just create a list first. To create a list first of all we need to give a name to our list which I have taken as “COURSE” followed by equals sign and finally enclosed …
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
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 …
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…

828 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