1
在Python語言中使用套接字庫函數時產生的異常是什麼? 我有異常錯誤的列表,但不知道哪個錯誤是爲套接字函數。 https://docs.python.org/2/library/errno.html 我想處理TCP套接字中的每個錯誤情況。套接字python中的異常列表
import socket
import sys
sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ('192.168.1.26', 56000)
while True:
try:
sock.connect(server_address)
break
except socket.error as e:
print "error while connecting ::%s",e
while True:
try:
# Send data
message = 'This is the message. It will be repeated.'
print >>sys.stderr, 'sending "%s"' % message
sock.sendall(message)
except socket.error as e:
print "error while sending ::%s",e
套接字錯誤在https://docs.python.org/2/library/socket.html?#socket.error –