I'm trying to make a simple client & server messaging program in python, and I keep getting the error "TypeError: 'str' does not support the buffer interface" and don't really even know what that means. I'm a beginner with python for the most part, and a complete begginer with networking.
I'm assuming for some reason I can't send string data? If this is the case, how would I send a string?
For reference, the example code I got most of this from was for python 2.x, and I'm doing this in Python 3, so I believe it's another kink to work out from version transition. I've searched around for the same problem, but can't really work out how to apply the same fixes to my situation.
Here's the beginning code for the server:
import socket
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind(("", 5000))
server_socket.listen(5)
print("TCP Server Waiting for client on port 5000")
while 1:
client_socket, address = server_socket.accept()
print("TCP Server received connect from: " + str(address))
while 1:
data = input("SEND(Type q or Q to quit):")
if(data == 'Q' or data == 'q'):
client_socket.send(data)
client_socket.close()
break;
else:
client_socket.send(data)
data = client_socket.recv(512)
if(data == 'q' or data == 'Q'):
client_socket.close()
break;
else:
print("Received: " + data)
StringIO.StringIO(data)
instead of justdata
. - Andrew Clarkif data in ('q', 'Q'):
- gskif data.lower() == "q":
. - Tim PietzckerTrue
fordata = ""
ordata = "qQ"
. - Tim Pietzcker