socket progamming : tcp_client "gai" error
<p>I'm setting up a simple client socket (my server socket works well). But I'm stuck by a lil bug. here's my code and here's the error. Cant find this errorr nowhere on the web.</p>

<pre><code>from socket import *
import sys 
host=socket.gethostname()
#host=127.0.0.1
serverPort= 12345
clientSocket =socket(AF_INET,SOCK_STREAM)
clientSocket.connect((127.0.0.1,serverPort))
msg= raw_input("Input text here:")
clientSocket.send(msg)
modmsg= clientSocket.recv(1024)
print "from server", modmsg
clientSocket.close()
</code></pre>

<p>the error:</p>

<pre><code>Traceback (most recent call last):
  File "tcp_client.py", line 5, in &lt;module&gt;
    clientSocket.connect((serverName,serverPort))
  File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
socket.gaierror: [Errno -5] No address associated with hostname
</code></pre>

<p>Your code is incorrect here (did you post the real code you ran?):</p>

<ol>
<li>host cannot be empty</li>
<li><code>connect</code> takes 1 argument and it's a tuple</li>
<li>if you do <code>from socket import *</code>, you cannot do <code>socket.socket</code></li>
</ol>

<p>fixed:</p>

<pre><code>import socket
import sys
host=socket.gethostname()
serverPort= 12345
clientSocket = socket.socket(AF_INET,SOCK_STREAM)
clientSocket.connect((host,serverPort))
msg= raw_input("Input text here:")
clientSocket.send(msg)
modmsg= clientSocket.recv(1024)
print "from server", modmsg
clientSocket.close()
</code></pre>

<p>now I get proper timeout when I run this code (I don't have the client) instead of your error.</p>

python serversocket tcpsocket