|
@@ -0,0 +1,26 @@
|
|
|
+import socket
|
|
|
+
|
|
|
+HOST = '192.168.51.102'
|
|
|
+PORT = 1
|
|
|
+
|
|
|
+s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
|
+s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
|
|
+s.bind((HOST, PORT))
|
|
|
+s.listen(5)
|
|
|
+
|
|
|
+print('server start at: %s:%s' % (HOST, PORT))
|
|
|
+print('wait for connection...')
|
|
|
+conn, addr = s.accept()
|
|
|
+print('connected by ' + str(addr))
|
|
|
+while True:
|
|
|
+ outdata = input('please input message: ')
|
|
|
+ conn.send(outdata.encode())
|
|
|
+ # while True:
|
|
|
+ indata = conn.recv(1024)
|
|
|
+# if len(indata) == 0: # connection closed
|
|
|
+ # conn.close()
|
|
|
+ # print('client closed connection.')
|
|
|
+ # break
|
|
|
+ print('recv: ' + indata.decode())
|
|
|
+ indata = conn.recv(1024)
|
|
|
+ print('recv: ' + indata.decode())
|