-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclientRe.py
41 lines (35 loc) · 974 Bytes
/
clientRe.py
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
36
37
38
39
40
41
'''
tcp client with reconnect
E-Mail : Mike_Zhang@live.com https://blog.csdn.net/zong596568821xp/article/details/78810839
'''
#! /usr/bin/env python
#-*- coding:utf-8 -*-
import os,sys,time
import socket
def doConnect(host,port):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try :
sock.connect((host,port))
except :
pass
return sock
def main():
host,port = "127.0.0.1",12345
print host,port
sockLocal = doConnect(host,port)
while True :
try :
msg = str(time.time())
sockLocal.send(msg)
print "send msg ok : ",msg
print "recv data :",sockLocal.recv(1024)
except socket.error :
print "\r\nsocket error,do reconnect "
time.sleep(3)
sockLocal = doConnect(host,port)
except :
print '\r\nother error occur '
time.sleep(3)
time.sleep(1)
if __name__ == "__main__" :
main()