Client Server Connection Program

Fredrik Lundh fredrik at pythonware.com
Tue Jul 4 12:07:25 EDT 2006


diffuser78 at gmail.com wrote:

> #/ usr/bin/env python
> # filename: tmc.py (CLIENT)
> 
> import socket
> import sys
> 
> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> 
> host = int(sys.argv[1])
> port = int(sys.argv[2])

the port number is an integer, but the host name/ip is obviously not an 
integer -- so why are you trying to convert it an integer ?

> s.connect((host,port))
> s.send(sys.argv[3])
> i = 0
> while True:
>     data = s.recv(1000000)
>     i+=1
>     if (i<5):
>         print data
>     if not data:
>         break
>     print 'received', len(data), 'bytes'
> s.close()
> 
> 
> Server is installed on machine 192.168.1.4 and Client is 192.168.1.2
> 
> 
> When I start server and the server is listening I start the clinet.
> 
> I started Client using ........
> 
> python tmc.py 192.168.1.4 2000 abcxyz
> 
> where 2000 is the port number  and abcxyz is the string I pass to
> server, I get the following error...
> 
> ValueError: invalid literal for int(): 192.168.1.4
> 
> How can I fix this ?

by reading the *entire* trackback, and looking at the line it tells you 
to look at, before you post.

</F>




More information about the Python-list mailing list