It can run but still has error.

njuien

New member
Joined
Feb 22, 2007
Messages
3
Programming Experience
Beginner
Hi all,
I have to write an application working as a delay server. It's named CApp.
CApp receives a message from a device and after changing something in the message 's data, it sends this message to the host. In the other way, it receives the response from host and sends back to the device.
CApp has worked but after several hours, it down. I have to restart it or sometime I have to restart my PC. I think the problem causes of the memory or something like that, but I can not find them.
I attached the code file below.
So someone can help me out of this trouble ?

Thank you so much.
 

Attachments

  • Connection Process.txt
    11.8 KB · Views: 26
Last edited by a moderator:
I actually don't know why it down, but here's an idea; instead of 'hanging' at the networkstream.Read blocking call every loop until actually there is data available you can do this and sleep thread:
VB.NET:
While True
    If [COLOR=darkgreen]streamNAC.DataAvailable[/COLOR] Then
        Dim streamNACLen As Int32 = CInt(ClientNAC.ReceiveBufferSize)
        Dim streamNACBytes1(streamNACLen) As Byte
        Dim i As Integer = [COLOR=darkgreen]streamNAC.Read[/COLOR](streamNACBytes1, 0, streamNACLen)
        '...
    Else
        Threading.Thread.[COLOR=darkgreen]Sleep[/COLOR](100)
    End If
End While
Depending on the rate you expect to receive messages you can modify the sleeping time.
 
Hi all,
I tried to debug the code and this is an error code: "Unable to read data from the transport connection. An existing connection was forcibly closed by remote host".
Anyone has an idea for me ?
Thanks
 
Back
Top