4

Server

import socket
import sys
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
host= 'VAC01.VACLab.com'
port=int(2000)
s.bind((host,port))
s.listen(1)
conn,addr =s.accept()
data=s.recv(100000)
s.close

CLIENT

import socket
import sys
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
host="VAC01.VACLab.com"
port=int(2000)
s.connect((host,port))
s.send(str.encode(sys.argv[1]))
s.close()

I want the server to receive the data that client sends.

I get the following error when i try this

CLIENT Side

Traceback (most recent call last): File "Client.py", line 21, in s.send(sys.argv[1]) TypeError: 'str' does not support the buffer interface

Server Side

File "Listener.py", line 23, in data=s.recv(100000) socket.error: [Errno 10057] A request to send or receive data was disallowed bec ause the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied

asked Apr 4, 2012 at 6:17
3
  • I think you may have to convert the str to bytes. Commented Apr 4, 2012 at 6:19
  • Do i do this str.encode(sys.argv[1]) ?? i did that ,the errors have stopped but the data is not transferring. Commented Apr 4, 2012 at 6:45
  • Are you still having trouble? Commented Apr 4, 2012 at 14:35

4 Answers 4

8

In the server, you use the listening socket to receive data. It is only used to accept new connections.

change to this:

conn,addr =s.accept()
data=conn.recv(100000) # Read from newly accepted socket
conn.close()
s.close()
answered Apr 4, 2012 at 6:22
Sign up to request clarification or add additional context in comments.

2 Comments

Still giving the same error at the client side. The server error got resolved.
but their are recv() and send() methods on socket object.
3

Your line s.send is expecting to receive a stream object. You are giving it a string. Wrap your string with BytesIO.

answered Apr 4, 2012 at 6:21

1 Comment

Do i do this str.encode(sys.argv[1]) ?? i did that ,the errors have stopped but the data is not transferring.
0

Which version of Python are you using? From the error message, I guess you are unintentionally using Python3. You could try your program with Python2 and it should be fine.

answered Apr 4, 2012 at 6:25

1 Comment

Vinod - Try it with Python2 then to know the difference.
-1

try to change the client socket to:

s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
Ripi2
7,2261 gold badge19 silver badges35 bronze badges
answered Jun 21, 2018 at 17:09

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.