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.
JadedTuna
1,8633 gold badges20 silver badges33 bronze badges
asked Oct 25, 2013 at 20:54
Razi Shafir
391 gold badge1 silver badge4 bronze badges
-
1Which line is the error on? Also, possible duplicate stackoverflow.com/questions/7162869/…CDspace– CDspace2013年10月25日 20:58:36 +00:00Commented Oct 25, 2013 at 20:58
-
1You 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.François Moisan– François Moisan2013年10月25日 20:58:57 +00:00Commented Oct 25, 2013 at 20:58
-
Please provide full tracebackJadedTuna– JadedTuna2013年10月25日 21:00:28 +00:00Commented Oct 25, 2013 at 21:00
-
2Possible duplicate of Python Sockets/SocketServer ConnectionZF007– ZF0072017年12月11日 16:26:59 +00:00Commented Dec 11, 2017 at 16:26
2 Answers 2
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".
answered Oct 25, 2013 at 21:02
JadedTuna
1,8633 gold badges20 silver badges33 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
DanGoodrick
HOST can also be the IP address of another machine on the network, right? e.g. '130.132.234.14'
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'.
phd
97.4k14 gold badges165 silver badges223 bronze badges
Comments
lang-py