<div dir="ltr">yah i did the search, and tried the solution, but it didn't work.... nice of you to have tried, though...<div><br></div><div>anyhow, i found where the problem is... on the client side it should be connect() instead of bind() in :</div>
<div><br></div><div>> tcpCliSock.bind(ADDR) </div><div><br></div><div>thanks <br><br><div class="gmail_quote">On Fri, Apr 6, 2012 at 4:59 PM, Evert Rol <span dir="ltr"><<a href="mailto:evert.rol@gmail.com">evert.rol@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">> i'm trying to implement a server that adds a time stamp to incoming text form a client.<br>
><br>
> the server's code is (but doesn't seem to have the problem as demoed by the error below:<br>
><br>
> from socket import *<br>
> from time import ctime<br>
><br>
> HOST = ''<br>
> PORT = 21567<br>
> BUFSIZ = 1024<br>
> ADDR =(HOST, PORT)<br>
><br>
> tcpSerSock = socket(AF_INET, SOCK_STREAM)<br>
><br>
> tcpSerSock.bind(ADDR)<br>
> tcpSerSock.listen(5)<br>
><br>
> while True:<br>
> print('waiting for connection ...')<br>
> tcpCliSock, addr =tcpSerSock.accept()<br>
> print('...connected from: ', addr)<br>
><br>
> while True:<br>
> data = tcpCliSock.recv(BUFSIZ)<br>
> if not data:<br>
> break<br>
> tcpCliSock.send('[{}] {}'.format(bytes(ctime(), 'utf-8'),data))<br>
><br>
> tcpCliSock.close()<br>
> tcpSerSock.close()<br>
><br>
><br>
><br>
> the client's code is:<br>
><br>
> from socket import *<br>
><br>
><br>
> HOST = 'localhost'<br>
> PORT = 21567<br>
> BUFSIZ = 1024<br>
> ADDR =(HOST, PORT)<br>
><br>
> tcpCliSock = socket(AF_INET, SOCK_STREAM)<br>
><br>
> tcpCliSock.bind(ADDR)<br>
><br>
> while True:<br>
> data=input('> ')<br>
> if not data:<br>
> break<br>
> tcpCliSock.send(data)<br>
> data = tcpCliSock.recv(BUFSIZ)<br>
> if not data:<br>
> break<br>
> print(data.decode('utf-8'))<br>
><br>
> tcpCliSock.close()<br>
><br>
> the problem is i get the following error when i enter some text:<br>
><br>
> Traceback (most recent call last):<br>
> File "C:\Python32\tsTclnt3.py", line 17, in <module><br>
> tcpCliSock.send(data)<br>
> TypeError: 'str' does not support the buffer interface<br>
<br>
</div></div>Did you try to search on the error string? That would have gotten you the solution (even) faster.<br>
The first two Google hits (and probably all the rest of them), tell me that Python 3's socket.send() method wants bytes as input, not str. See <a href="http://docs.python.org/py3k/library/socket.html#socket.socket.send" target="_blank">http://docs.python.org/py3k/library/socket.html#socket.socket.send</a><br>
<br>
Hope that helps,<br>
<br>
Evert<br>
<br>
<br>
><br>
> can you help?<br>
> _______________________________________________<br>
> Tutor maillist - <a href="mailto:Tutor@python.org">Tutor@python.org</a><br>
> To unsubscribe or change subscription options:<br>
> <a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
<br>
</blockquote></div><br></div></div>