socketpythonbind
『壹』 python socket報錯[WinError 10061] 由於目標計算機積極拒絕,無法連接。 是什麼意思
127.0.0.1 8900是你本機電腦的埠,別的電腦連不上,有可能沒有啟用監聽890埠的服務,也有可能電腦安裝了安全防護軟體,禁止其它機器訪問不明埠。你查一下對方機器情況。
『貳』 python socket send 錯誤:TypeError: 'str' does not support the buffer interface
python3.2 socket.send 修改傳送數據必須是bytes
http://docs.python.org/py3k/library/socket.html
改成 s.send(b'Hello')
這里有官網的例子:
# Echo server program
import socket
HOST = '' # Symbolic name meaning all available interfaces
PORT = 50007 # Arbitrary non-privileged 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)
while True:
data = conn.recv(1024)
if not data: break
conn.send(data)
conn.close()
# Echo client program
import socket
HOST = 'daring.cwi.nl' # The remote host
PORT = 50007 # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.send(b'Hello, world')
data = s.recv(1024)
s.close()
print('Received', repr(data))