Socket timeout in IronPython

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oberon
    New Member
    • Mar 2008
    • 14

    Socket timeout in IronPython

    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:

    [code=python]from socket import *
    s = socket(AF_INET, SOCK_STREAM)
    s.bind(('', 8888))
    s.listen(5)
    s.settimeout(2)
    client, addr = s.accept()[/code]

    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.)
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    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.

    Comment

    • oberon
      New Member
      • Mar 2008
      • 14

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

      Comment

      • bvdet
        Recognized Expert Specialist
        • Oct 2006
        • 2851

        #4
        It was a shot in the dark. Documentation suggests setting the timeout as soon as a socket is created.

        Comment

        Working...