I am trying to send messages between two computers over LAN. For some reason, the client side is hanging and not sure why.
Server:
#echo server
import socket
HOST = '192.168.1.135'
PORT = 50017 # port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()
print ('Connected by', addr)
conn.send("Hello Client")
conn.send("How are you")
conn.close()
print("Connection", addr, "Closed")
Client:
import socket
HOST = '192.168.1.135' # The remote host
PORT = 50017 # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
while 1:
data = s.recv(1024)
if not data: break
print(data)
s.close()
I am trying to send messages between two computers over LAN. For some reason, the client side is hanging and not sure why.
Server:
#echo server
import socket
HOST = '192.168.1.135'
PORT = 50017 # port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()
print ('Connected by', addr)
conn.send("Hello Client")
conn.send("How are you")
conn.close()
print("Connection", addr, "Closed")
Client:
import socket
HOST = '192.168.1.135' # The remote host
PORT = 50017 # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
while 1:
data = s.recv(1024)
if not data: break
print(data)
s.close()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.