Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python, socket.error: [Errno 10049]

Tags:

python

sockets

Working on a base for a simple chat client, and got the following error:
socket.error: [Errno 10049] The requested address is not valid in its context

The code is:

from socket import *
HOST = ''
PORT = 8000
s = socket(AF_INET, SOCK_STREAM)
s.connect((HOST, PORT))
i = True
while i is True:
    msg = raw_input("Write A MSG: ")
    s.send(msg)
    print "Awaiting reply"
    reply = s.recv(1024)
    print "Recived: ", repr(reply)

s.close()

Thanks for helping.

like image 253
Razi Shafir Avatar asked Dec 04 '25 14:12

Razi Shafir


1 Answers

The error is:

...
s.connect((HOST, PORT))

And it is because HOST = "". You may use HOST = "" when binding sockets. But when connecting, you should use HOST = "localhost" or HOST = "someaddr.com".

like image 78
JadedTuna Avatar answered Dec 07 '25 04:12

JadedTuna