By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,551 Members | 1,159 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,551 IT Pros & Developers. It's quick & easy.

Socket timeout in IronPython

P: 14
Hi,
I hope it's ok for me to place an IronPython question in this forum(?).

I am running IronPython 1.1.2 and Python 2.5.
OS is Windows XP SP3.

Currently I'm developing a lightweight test framework. In short, there are two scripts that control one hardware device each. The hardware devices are communicating wirelessly. I am using IronPython because I am then able to use some needed .NET libraries seamlessly.

One functionality I need in the scripts is a way of synchronizing them with each other. The scripts are running in separate threads, so I need interprocess communication. I also need the synchronization to be able to timeout, to avoid the script from hanging indefinitely.

I have found that sockets would fit my needs well. One script binds and listens to a socket, and the other script connects to the same socket, allowing them to exchange messages.

Now, my problem is that I am not able to make the timeout of the socket to work in IronPython. When I test the same in Python it works like a charm. Here is the isolated code for demonstrating the problem:

Expand|Select|Wrap|Line Numbers
  1. from socket import *
  2.  s = socket(AF_INET, SOCK_STREAM)
  3.  s.bind(('', 8888))
  4.  s.listen(5)
  5.  s.settimeout(2)
  6.  client, addr = s.accept()
The code snippet will timeout when run in Python, but not in IronPython.

Is the implementation of socket in IronPython lacking the ability of timeout?

(Suggestions to other approaches to my problem would also be greatly appreciated.)
Dec 7 '08 #1
Share this Question
Share on Google+
3 Replies


bvdet
Expert Mod 2.5K+
P: 2,851
oberon,

It's OK to post IronPython questions here. Unfortunately, I don't know IronPython. Your explanation of the problem is excellent. Try moving s.settimeout(2) before s.listen(5). Thanks for posting.
Dec 7 '08 #2

P: 14
Hi,
moving s.settimeout(2) before s.listen(5) doesn't seem to make any difference, neither in IronPython or Python.
Dec 7 '08 #3

bvdet
Expert Mod 2.5K+
P: 2,851
It was a shot in the dark. Documentation suggests setting the timeout as soon as a socket is created.
Dec 7 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.