File: recv_oneshot

package info (click to toggle)
python-irodsclient 3.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,352 kB
  • sloc: python: 16,650; xml: 525; sh: 104; awk: 5; sql: 3; makefile: 3
file content (35 lines) | stat: -rwxr-xr-x 665 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python
from __future__ import print_function
import sys, os, time
from socket import *
import getopt

def try_connect(host,port):
    try:
        s=socket(AF_INET,SOCK_STREAM)
        s.connect((host,port))
        return s
    except:
        s.close()
        return None

# Options:
#
# -t timeout
# -h host
# -p port

t = now = time.time()
opts = dict(getopt.getopt(sys.argv[1:],'t:h:p:')[0])

host = opts['-h']
port = int(opts['-p'])
timeout = float(opts['-t'])

while time.time() < now + timeout:
      time.sleep(1)
      s = try_connect(host, port)
      if s:
          print(s.recv(32767).decode('utf-8'),end='')
          exit(0)
exit(1)