2

I can telnet to a certain host and port no problem and issue commands. However when i try to script a socket connection (using nmap NSE and Lua) to the same host and port, it fails with the following error message:

|_sockettest: Trying to receive through a closed socket

the socket connect part of my code is here:

local msg
local response
msg = "hello\n"

local socket = nmap.new_socket()
socket:set_timeout(150000)
socket:send(msg)

response,data = socket:receive()
return data

I think the data is sending ok. The server should just echo back what i sent. Does anyone know what the problem could be?

RBerteig
  • 41,948
  • 7
  • 88
  • 128
greatodensraven
  • 281
  • 1
  • 7
  • 14
  • 1
    I see no reason for the downvote. The underlying issue was a simple mistake, but the question had sufficient code to see the issue and resolve the problem. That is what SO is about and should be rewarded. – RBerteig Jun 30 '11 at 00:54

1 Answers1

3

You need to call socket:connect before receiving (and before sending). Seriously, read that code you wrote. Where did you specify to whom you're sending ?

cnicutar
  • 178,505
  • 25
  • 365
  • 392