By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,446 Members | 1,623 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,446 IT Pros & Developers. It's quick & easy.

Client Server Connection Program

P: n/a
Hi,

I have the following code for a cline and server which I got from a
small tutorial on the web.

#!/ usr/bin/env python
# tms.py (SERVER)

import socket
import sys

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = ''
port = int(sys.argv[1])

s.bind((host,port))
s.listen(1)
conn, addr = s.accept()
print 'client is at', addr

data = conn.recv(1000000)
data = data * 1000

z = raw_input()
conn.send(data)
conn.close()

AND

#/ 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])

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 ? I am trying to achieve the most basic level of
networking between a client and a server.

Every help is appreciated.

Jul 4 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
di********@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>

Jul 4 '06 #2

P: n/a
removing int frrom host = int(sys.argv[1]) fixed the problem. Thanks
Fred!!!

Fredrik Lundh wrote:
di********@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>
Jul 4 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.