Need help with this code...

  • Thread starter Thread starter Terry Olsen
  • Start date Start date
T

Terry Olsen

Here's the situation...

I've got a working program that sends commands to various computers using
the RemoteExec service. There's one pc that doesn't seem to reply. It
accepts the connection but never replies. So my program just sits there in
a "not responding" state waiting for the reply and I have to "end-task" it.
Here's the code where it locks up. Look for the 3rd "debug.writeline" in
the code...that's where it locks up. Is there a way to have this timeout?
Or otherwise abort the function and allow the program to continue on with
the next pc in the list?

Thanks.

'Create a socket connection with the specified server & port (512 is the
remote execute port)

Dim s As Socket = connectSocket(txtRemotePC.Text, 512)

If s Is Nothing Then

MsgBox("Unable to connect to Remote PC", MsgBoxStyle.Critical)

Exit Sub

End If



'Send message to the repeater

Try

s.Send(ByteGet, ByteGet.Length, SocketFlags.None)

Catch ex As SocketException

Debug.WriteLine("s.Send: " & ex.Message)

Catch ex As Exception

Debug.WriteLine("s.Send: " & ex.Message)

End Try



'Recieve the response from the repeater

Try

Debug.WriteLine("s.Receive") <-- locks up after writing this to
the debug window.

bytes = s.Receive(RecvBytes, RecvBytes.Length, SocketFlags.None)

Debug.WriteLine("s.Receive complete") <--never gets here, never
throws an exception

Catch ex As SocketException

Debug.WriteLine("s.Receive: " & ex.message)

Catch ex As Exception

Debug.WriteLine("s.Receive: " & ex.Message)

End Try
 
Here's the situation...

I've got a working program that sends commands to various computers using
the RemoteExec service. There's one pc that doesn't seem to reply. It
accepts the connection but never replies. So my program just sits there in
a "not responding" state waiting for the reply and I have to "end-task" it.
Here's the code where it locks up. Look for the 3rd "debug.writeline" in
the code...that's where it locks up. Is there a way to have this timeout?
Or otherwise abort the function and allow the program to continue on with
the next pc in the list?

Thanks.

'Create a socket connection with the specified server & port (512 is the
remote execute port)

Dim s As Socket = connectSocket(txtRemotePC.Text, 512)

If s Is Nothing Then

MsgBox("Unable to connect to Remote PC", MsgBoxStyle.Critical)

Exit Sub

End If



'Send message to the repeater

Try

s.Send(ByteGet, ByteGet.Length, SocketFlags.None)

Catch ex As SocketException

Debug.WriteLine("s.Send: " & ex.Message)

Catch ex As Exception

Debug.WriteLine("s.Send: " & ex.Message)

End Try



'Recieve the response from the repeater

Try

Debug.WriteLine("s.Receive") <-- locks up after writing this to
the debug window.

bytes = s.Receive(RecvBytes, RecvBytes.Length, SocketFlags.None)

Debug.WriteLine("s.Receive complete") <--never gets here, never
throws an exception

Catch ex As SocketException

Debug.WriteLine("s.Receive: " & ex.message)

Catch ex As Exception

Debug.WriteLine("s.Receive: " & ex.Message)

End Try

You can set a Receive timeout value...

' all receives will timeout after 5 seconds of waiting for data...
s.SetSocketOption (SocketOptionLevel.Socket,
SocketOptionName.ReceiveTimeOut, 5000)

HTH
 
You can set a Receive timeout value...

' all receives will timeout after 5 seconds of waiting for data...
s.SetSocketOption (SocketOptionLevel.Socket,
SocketOptionName.ReceiveTimeOut, 5000)

Thanks! That worked like a charm. I set the timeout to 15 minutes
tho...sometimes it takes that long for a response.
 
Back
Top