I was developing a program that individual elements from the list to another machine (sender-server,reciever-client). I am sharing my program below
-------------------------client.py------------------------
import socket # Import socket module
s = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name
port = 4444 # Reserve a port for your service.
s.connect((host, port))
s.send("Hi server1")
while True:
a=int(s.recv(1024))
tmp=0
while tmp<=a:
print s.recv(1024)
tmp=tmp+1
----------------------------------server.py------------------------------
import socket # Import socket module
s = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name
port = 4444 # Reserve a port for your service.
s.bind((host, port)) # Bind to the port
s.listen(5)
print "Server listening"
while True:
c=s.accept()
b=['a','b']
d=len(b)
a=str(d)
c.send(a)
for i in range(0,len(b)):
tmp=str(b[i])
c.send(tmp)
When I run both server and client, the server raises this:
Traceback (most recent call last):
File "server.py", line 14, in <module>
c.send(a)
AttributeError: 'tuple' object has no attribute 'send'
client.py.(conn, addr) where conn is a socket object. You have to use that object in line 14 to send things. What you're doing is calling send() from the entire tuple which has no method named send and so the AttributeError gets raised. I'd suggest changing line 11 to c = s.accept()[0].If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With