-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsimple_ser.py
More file actions
executable file
·53 lines (35 loc) · 826 Bytes
/
Copy pathsimple_ser.py
File metadata and controls
executable file
·53 lines (35 loc) · 826 Bytes
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
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/python
#coding=utf-8
import socket
import os
import sys
import thread
import time
def ser_recv(connfd, cliaddr):
while True:
buf = connfd.recv(4096)
print buf
thread.exit_thread()
def ser_send(connfd, cliaddr):
print cliaddr
connfd.sendall('welcome to my server\n')
t = thread.start_new_thread(ser_recv, (connfd, cliaddr))
while True:
print '#',
buf = sys.stdin.readline()
connfd.sendall(buf)
thread.exit_thread()
def server(host, port):
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, port))
s.listen(3)
while True:
time.sleep(1)
connfd, cliaddr = s.accept()
t = thread.start_new_thread(ser_send, (connfd, cliaddr))
if __name__ == '__main__':
# port = 1235
# host = '192.168.0.112'
host = sys.argv[1]
port = int(sys.argv[2])
server(host, port)