Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

After connecting with socket and sending data, unable to recv

Status
Not open for further replies.

cyli

Programmer
Aug 15, 2001
6
US
I'm trying to write a little script to send data to another machine, and just read any message I get in return.

so I do something like:

import socket
import select

s = socket.socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
s.connect((<host>, <port>))
s.send('sometext')

[input, output, error] =
select([s.fileno()], [], [])
if s.fileno() in input:
result = s.recv(1024)
<do some stuff with result>
else:
<do something else>

It sends the data correctly, and I am portscanning my network and I should be getting some kind of response, but the select just blocks. I know I can set a timeout and set the socket to be non-blocking, but I know that the remote machine has sent a response and I don't know why I am not receiving it.

Can anyone help?
 
Try to put code:
[input, output, error] =
select([s.fileno()], [], [])
if s.fileno() in input:
result = s.recv(1024)
<do some stuff with result>
else:
<do something else>

into infinite loop
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top