3

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.

4
  • 1
    Which line is the error on? Also, possible duplicate stackoverflow.com/questions/7162869/… Commented Oct 25, 2013 at 20:58
  • 1
    You can look here for windows error codes which seems to be the platform you are using. I suspect the problem you have is that your HOST variable is empty. Commented Oct 25, 2013 at 20:58
  • Please provide full traceback Commented Oct 25, 2013 at 21:00
  • 2
    Possible duplicate of Python Sockets/SocketServer Connection Commented Dec 11, 2017 at 16:26

2 Answers 2

4

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".

Sign up to request clarification or add additional context in comments.

1 Comment

HOST can also be the IP address of another machine on the network, right? e.g. '130.132.234.14'
2

IP address (HOST) is not correct. If you want to access it from local computer you can use '127.0.0.1' or 'localhost'. To access from anywhere use '0.0.0.0'.

Comments

Your Answer

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.