Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

python UDP how do I specify an IP destination?

Posted on 2014-02-26
3
Medium Priority
?
487 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 2000 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article will show the steps for installing Python on Ubuntu Operating System. I have created a virtual machine with Ubuntu Operating system 8.10 and this installing process also works with upgraded version of Ubuntu OS. For installing Py…
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 strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
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…

704 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