7 Replies - 1110 Views - Last Post: 23 March 2013 - 09:02 AM Rate Topic: -----

#1 Highest bidder  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 19
  • Joined: 23-November 12

Python networking UDP problem

Posted 22 March 2013 - 05:40 AM

Hello guys, i am working on a python program for my bachelor thesis and i have come across a very odd situation...
I hope you can help. I am trying to send 16 packets over the network with the following lines:

for x in packets:
	s.sendto(x, (host, port))



but the receiver will only get 10 packets out of 16...
Now here is the catch: i added a print statement to see if the loop on the server side is proceeding normaly
so it became like this:

for x in packets:
	print "in loop"
	s.sendto(x, (host, port))



And that works perfectly!!!! Then i tried:

for x in packets:
	time.sleep(0.001)
	s.sendto(x, (host, port))



Which also works perfectly, and then:

for x in packets:
	pass
	s.sendto(x, (host, port))



Which also works!!!! Why the first code example isnt working? Its not big deal for me to add a pass statement but i am extremely curious, plus going around the problem doesnt solve it...

Any suggestions?

Is This A Good Question/Topic? 0
  • +

Replies To: Python networking UDP problem

#2 Highest bidder  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 19
  • Joined: 23-November 12

Re: Python networking UDP problem

Posted 22 March 2013 - 05:51 AM

View PostHighest bidder, on 22 March 2013 - 05:40 AM, said:

for x in packets:
	pass
	s.sendto(x, (host, port))



This isnt working either, my bad...
Was This Post Helpful? 0
  • +
  • -

#3 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Python networking UDP problem

Posted 22 March 2013 - 08:41 AM

From my perspective, it appears the issues are occuring because the packets are being sent too quickly. The other examples have extra code that needs to get processed which slows things down a little. Since pass does nothing, it makes sense that it didn't have any effect.

Perhaps your receiver can only receive a certain number of packets per second?

EDIT:
So, this sort of programming isn't my expertise, but I'm doing my best for ya boss. perhaps you may want to adjust socket.SO_RCVBUF
I'm basing this off of: this

This post has been edited by atraub: 22 March 2013 - 09:17 AM

Was This Post Helpful? 0
  • +
  • -

#4 Highest bidder  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 19
  • Joined: 23-November 12

Re: Python networking UDP problem

Posted 22 March 2013 - 03:06 PM

first of all i apologize for the duplicate topic but the browser told me that the server was busy so i had to make another one without checking if the previous had made it into the forum...

So you basically say that it works similar to a denial of service attack? (thats what i thought) but could this affect the host's loop-back address too? (127.0.0.1)? i was just hopping that i could send the packets as fast as possible, but i guess i will have to settle with a small time.sleep delay...
Was This Post Helpful? 0
  • +
  • -

#5 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Python networking UDP problem

Posted 22 March 2013 - 03:34 PM

I'm knowlegable in general Python, however, my networking skills are probably on par with yours ^_^ hopefully someone with more specific knowledge will weigh in.

Rather than time.sleep, I'd recommend adjusting socket.SO_RCVBUF and checking to see if that works... to my understanding, that's precisely why that variable exists. For many, many reasons, that would be preferable to the time.sleep solution.

EDIT:

View PostHighest bidder, on 22 March 2013 - 05:06 PM, said:

first of all i apologize for the duplicate topic but the browser told me that the server was busy so i had to make another one without checking if the previous had made it into the forum...

It happens, no worries.

This post has been edited by atraub: 22 March 2013 - 03:36 PM

Was This Post Helpful? 0
  • +
  • -

#6 Highest bidder  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 19
  • Joined: 23-November 12

Re: Python networking UDP problem

Posted 23 March 2013 - 01:46 AM

Ok thank you very much, i will look into it :)
Was This Post Helpful? 0
  • +
  • -

#7 Highest bidder  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 19
  • Joined: 23-November 12

Re: Python networking UDP problem

Posted 23 March 2013 - 02:15 AM

View Postatraub, on 22 March 2013 - 03:34 PM, said:

socket.SO_RCVBUF


I finally found it on the internet, but i am not sure how to use it and it doesn't seem to be any good tutorials or examples out there! socket.SO_RCVBUF is 4098 and it wont change, but i dont know what to do with it. :dozingoff:/> No idea on how to use it, so i will probably stick with the time.sleep(0.001), after all one millisecond delay is not as bad as it seems, however if you have some time and you know how to do it, give me a guideline :D/>
Was This Post Helpful? 0
  • +
  • -

#8 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Python networking UDP problem

Posted 23 March 2013 - 09:02 AM

Did you try socket.SO_RCVBUF = 2049?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1