简体   繁体   中英

socket.error: [Errno 10057] no socket connection

i'm building a simple HTTP proxy server.when i try to send a respond from my server to the proxy server after the server got data from the proxy i get "socket.error: [Errno 10057] no socket connection" in my server were it is written "pro_soc.send(data_web)"

this is my server :

pro_soc = socket.socket()
#connect 
pro_soc.bind(("127.0.0.1", 8001))
# wait for proxy request
pro_soc.listen(1)
print "listening...."
client_soc, client_address= pro_soc.accept()
# receive proxy message
client_url = client_soc.recv(1024)
#send webpage data to proxy
file_web = open(client_url,"r")
data_web = file_web.read()
print data_web
pro_soc.send(data_web)
#close
file_web.close()
client_soc.close()
pro_soc.close()

this is my proxy server :

client_soc = socket.socket()
server_soc = socket.socket()
# connect to socket
client_soc.bind(("127.0.0.1", 8000))
# wait for client request
client_soc.listen(1)
print "listening...."
client_soc, client_address= client_soc.accept()
# receive client message
client_url = client_soc.recv(1024)
#send it to server
server_soc.connect(("127.0.0.1", 8001))
server_soc.send(client_url)
web_data = server_soc.recv(1024)
print web_data
new_data = web_data.replace("japan","china")
new_html = open("newHtml.html","w")
new_html.write(new_data)
webbrowser.open_new_tab("newHtml.html")
# close connection and file
client_soc.close()
server_soc.close()
new_html.close()

can you tell me where the bug is ?

thank you ♥

Be careful with your ports.

Your server is using one socket to listen and send data. 8001

However, your proxy server is listening on 8000 and sending on 8001 . Your proxy server will never receive a communication on port 8001 since it is not listening.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM