0

I am serving a test file as follows:

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
facebook = open("sources/facebook.htm","rb")
listen = ("localhost", 2000)
sock.bind(listen)
sock.listen(1)
while True:
 connection, client_address = sock.accept()
 print("Got a Connection from: " + client_address[0])
 sock.send(facebook.read(10000000))

I have downloaded facebook homepage to test connections but when I connect to this page, it gives the following error:

Got a Connection from: 127.0.0.1 Traceback (most recent call last): File "C:\Users\Export.1\blocker.py", line 11, in sock.send(facebook.read(1000000)) OSError: [WinError 10057] A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied

How can I fix it?

asked Jul 4, 2017 at 16:29

1 Answer 1

5

The error occurs because you are sending reply to the server socket instead of client, try changing

sock.send(facebook.read(10000000))

to

connection.send (facebook.read(1000000))

instead

President James K. Polk
42.3k35 gold badges114 silver badges149 bronze badges
answered Jul 4, 2017 at 16:50
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.