Hello all, I'm trying to run a simple client/server socket progaram from a refrence of the net to get my feet wet a bit with network programming. I can connect fine but can't seem to send data from the client due to the fact python is saying its of type"str" and not of type "string". I searched google and the forum for an answer but can't seem to find anything. Here is the code and error I'm getting.
#simple illustration client/server pair; client program sends a string #to server, which echoes it back to the client (in multiple copies), #and the latter prints to the screen #this is the client import socket import sys #create a socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #connect to server host = "127.0.0.1" #server address port = 2345 #server listening port s.connect((host, port)) data = "stuff" s.send(data) #send test string to server #read echo i = 0 while(1): data = s.recv(1000000) #read upto 1000000 bytes i += 1 if (i < 5): #look at only first part of message print(data) if not data: #if end data, leave loop break print("recieved", len(data), "bytes") #close the connection s.close()
And the error is this.
Traceback (most recent call last): File "C:\Users\Nancy\Desktop\Desktop\wills stuff\programs\network\testclient.py", line 18, in <module> s.send(data) #send test string to server TypeError: send() argument 1 must be string or buffer, not str