473,399 Members | 2,278 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Client Server Connection Program

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
2 2221
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: laststubborn | last post by:
Hi ; I m trying to create Merge Replication. I was able to create the replication on the same machine, however my aim is to use client machine and do all the neessary work on the client machine...
4
by: Webster | last post by:
Hello, What's the best way to run a client-server interaction using some standardized protocol such as nntp?? That is, should you run a thread that just does a receive loop from the server so...
0
by: palvin | last post by:
Any sample or any open source SSL libary to use to support client server connection on SSL.
0
by: swisSL | last post by:
Hi, im developing a client server socket program in C#.net When a client is connected to the server socket is there a function or way to detect the clients IP Adderss. Thank you.. swisSL
4
by: shreedhan | last post by:
hi i am trying to write a simple client server chat program. the code of server program is: #define PORT 9999 int main() { struct sockaddr_in server_addr,client_addr;
0
by: cherryblossom | last post by:
hii im developing a client server connection. i have a set of servers.. and i connect the client to one of these servers using the following code using System; using System.IO;
4
by: Babloo | last post by:
Hi everyone, i wanted to implement a client- server connection and transfer a file over the network. i was able to implement a normal set up where in i was able to send chat messages and small...
10
by: Elaine121 | last post by:
Hi i've been batteling for hours and can't seem to find the problem. When my server runs and I press the connect button the gui freezes until the client gui is terminated.. only then the gui becomes...
0
by: bushramemon | last post by:
hello,,now i m working on multi-threaded client server socket program in which there is one server and multiple clients.........these both are just giving acknowledge to each other that server...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.