[英]python-serial OSError: [Errno 11] Resource temporarily unavailable
[英]Fix “[Errno 11] Resource temporarily unavailable” in Python 2.x.x?
我有兩個腳本server.py
和talk.py
server.py
應該監聽連接並使用talk.py
數據
它在localhost上完美運行,即如果我在同一台機器上的不同終端上運行server.py
和talk.py
...
a) talk.py
請求字符串b) server.py
a)中的字符串並將其打印在運行server.py
的終端中
就像我說的,腳本在本地機器Ubuntu上運行正常。
當我將server.py
部署到GCP VM實例時,似乎運行正常,但是,為什么我在本地計算機上運行talk.py
代碼以通過外部Web IP地址talk.py
連接到server.py
套接字給出錯誤代碼
Traceback (most recent call last):
File "talk.py", line 11, in <module>
s.connect(('35.247.28.0', port))
File "/usr/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 11] Resource temporarily unavailable
#server.py
# first of all import the socket library
import socket
# next create a socket object
s = socket.socket()
print "Socket successfully created"
# reserve a port on your computer in our
# case it is 12345 but it can be anything
port = 12345
# Next bind to the port
# we have not typed any ip in the ip field
# instead we have inputted an empty string
# this makes the server listen to requests
# coming from other computers on the network
s.bind(('', port))
print "socket binded to %s" %(port)
# put the socket into listening mode
s.listen(5)
print "socket is listening"
# a forever loop until we interrupt it or
# an error occurs
while True:
# Establish connection with client.
c, addr = s.accept()
print 'Got connection from', addr
# Get data from client
"""
try:
data = c.recv(1024)
except IOError as e:
print e
"""
print data
if not data:
break
# Send back reversed data to client
c.sendall(data)
# send a thank you message to the client.
#c.send('\n Thank you for sending message!!!!')
# Close the connection with the client
c.close()
# talk.py
# first of all import the socket library
import socket
# next create a socket object
s = socket.socket()
print "Socket successfully created"
# reserve a port on your computer in our
# case it is 12345 but it can be anything
port = 12345
# Next bind to the port
# we have not typed any ip in the ip field
# instead we have inputted an empty string
# this makes the server listen to requests
# coming from other computers on the network
s.bind(('', port))
print "socket binded to %s" %(port)
# put the socket into listening mode
s.listen(5)
print "socket is listening"
# a forever loop until we interrupt it or
# an error occurs
while True:
# Establish connection with client.
c, addr = s.accept()
print 'Got connection from', addr
print data
if not data:
break
# Send back reversed data to client
c.sendall(data)
# send a thank you message to the client.
#c.send('\n Thank you for sending message!!!!')
# Close the connection with the client
c.close()
看起來像路由/安全問題而不是代碼。 這可能會有所幫助: 如何移植Google Compute Engine實例?
[edit]另一種資源: 如何在Google Compute Engine中打開特定端口,例如9090
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.