相关疑难解决方法(0)

为什么我在Python中收到错误"连接被拒绝"?(插座)

我是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)

python sockets

52
推荐指数
2
解决办法
17万
查看次数

标签 统计

python ×1

sockets ×1