2020-03-04 03:26:07 +00:00
|
|
|
# Simple test of a TCP server and client transferring data
|
|
|
|
|
|
|
|
import socket
|
|
|
|
|
|
|
|
PORT = 8000
|
|
|
|
|
|
|
|
# Server
|
|
|
|
def instance0():
|
|
|
|
multitest.globals(IP=multitest.get_network_ip())
|
|
|
|
s = socket.socket()
|
|
|
|
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
|
|
|
s.bind(socket.getaddrinfo("0.0.0.0", PORT)[0][-1])
|
2022-02-16 16:44:17 +00:00
|
|
|
s.listen()
|
2020-03-04 03:26:07 +00:00
|
|
|
multitest.next()
|
|
|
|
s2, _ = s.accept()
|
|
|
|
print(s2.recv(16))
|
|
|
|
s2.send(b"server to client")
|
2022-01-17 13:15:57 +00:00
|
|
|
s2.close()
|
2020-03-04 03:26:07 +00:00
|
|
|
s.close()
|
|
|
|
|
|
|
|
|
|
|
|
# Client
|
|
|
|
def instance1():
|
|
|
|
multitest.next()
|
|
|
|
s = socket.socket()
|
|
|
|
s.connect(socket.getaddrinfo(IP, PORT)[0][-1])
|
|
|
|
s.send(b"client to server")
|
|
|
|
print(s.recv(16))
|
|
|
|
s.close()
|