我是Sockets的新手,请原谅我完全缺乏理解.
我有一个服务器脚本(server.py):
#!/usr/bin/python
import socket #import the socket module
s = socket.socket() #Create a socket object
host = socket.gethostname() #Get the local machine name
port = 12397 # Reserve a port for your service
s.bind((host,port)) #Bind to the port
s.listen(5) #Wait for the client connection
while True:
c,addr = s.accept() #Establish a connection with the client
print "Got connection from", addr
c.send("Thank you for connecting!")
c.close()
Run Code Online (Sandbox Code Playgroud)
和客户端脚本(client.py):
#!/usr/bin/python
import socket #import socket module
s = socket.socket() #create a socket object …Run Code Online (Sandbox Code Playgroud)