473,395 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Need help with this code...

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
Nov 21 '05 #1
2 1323
On Mon, 9 Aug 2004 17:53:14 -0600, Terry Olsen wrote:
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
--
Tom Shelton [MVP]
Nov 21 '05 #2
>
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.
Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: drdoubt | last post by:
using namespace std In my C++ program, even after applying , I need to use the std namespace with the scope resolution operator, like, std::cout, std::vector. This I found a little bit...
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
11
by: my-wings | last post by:
I think I've painted myself into a corner, and I'm hoping someone can help me out. I have a table of books (tblBooks), which includes a field (strPubName) for Publisher Name and another field...
7
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
48
by: Chad Z. Hower aka Kudzu | last post by:
A few of you may recognize me from the recent posts I have made about Indy <http://www.indyproject.org/indy.html> Those of you coming to .net from the Delphi world know truly how unique and...
4
by: Phil | last post by:
k, here is my issue.. I have BLOB data in SQL that needs to be grabbed and made into a TIF file and placed on the client (could be in temp internet dir). The reason we need it in TIF format is...
2
by: Keith Kowalski | last post by:
I anm opening up a text file reading the lines of the file that refer to a tif image in that file, If the tif image does not exist I need it to send an email stating that the file doesn't exist...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
4
by: Quas.co.ua | last post by:
Hello all. I need your help. I need C compler to make demo of some technologie. This C compiler I need to write program which after run will be located in one segment of memory and it...
20
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.