sometime when i run a program, i end up with an error, then for exp the next day that i run the same program ( exaclty as i ran it before, same conditions ), the program runs fine, its happened several times. whats the reason? :confused:
sometime when i run a program, i end up with an error, then for exp the next day that i run the same program ( exaclty as i ran it before, same conditions ), the program runs fine, its happened several times. whats the reason? :confused:
software gremlins.
this is the case i have now!!
when the server app. is started before the client, i have no problems, but when client is started before server, sometimes it works,but most of the times an exeption is thrown in the "DATARECEIVER" sub on the line >>
bytesreceived = TCPClient.GetStream.EndRead(ar)
thanks....
public sub main()
StartTcpClient()
end sub
Public Sub StartTcpClient()
thread = New System.Threading.Thread(AddressOf ConnectToServer)
thread.IsBackground = True
Thread.Start()
End Sub
Public Sub ConnectToServer()
TCPClient = New System.Net.Sockets.TcpClient()
Connecting()
End Sub
Public Sub Connecting()
Try
Trace.Write("Connecting to server ... ")
ClientStatus = Status.Connecting
TCPClient.Connect(Config.Settings_ServerPath, Config.Settings_ServerPort)
' TCPClient = New System.Net.Sockets.TcpClient(Config.Settings_ServerPath, Config.Settings_ServerPort)
Trace.WriteLine("Connected")
DataSender("CONNECT|" & Config.Settings_ClientName)
ClientStatus = Status.WaitingOnServer
TCPClient.GetStream.BeginRead(Buffer, 0, BUFFER_SIZE, AddressOf Receiver, Nothing)
Catch
Trace.WriteLine("Disconnected")
ClientStatus = Status.Disconnected
Thread.Sleep(5000)
Connecting()
End Try
End Sub
Private Sub Receiver(ByVal ar As System.IAsyncResult)
Dim bytesreceived As Integer
Dim msg As String
Try
bytesreceived = TCPClient.GetStream.EndRead(ar)
If bytesreceived < 2 Then
Trace.WriteLine("Unable to receive data, Disconnected")
ClientStatus = Status.Disconnected
Exit Sub
End If
msg = System.Text.Encoding.ASCII.GetString(Buffer, 0, BUFFER_SIZE - 2)
DataReceived(msg)
Buffer.Clear(Buffer, 0, BUFFER_SIZE)
TCPClient.GetStream.BeginRead(Buffer, 0, BUFFER_SIZE, AddressOf Receiver, Nothing)
Catch e As System.Exception
Trace.WriteLine("ECXEPTION THROWN >> (receiver error )" & e.Message)
End Try
End Sub
What is the exception message and stack trace?
Message >> Unable to read data from the transport connection.
Trace >> at System.Net.Sockets.NetworkStream.EndRead (IAsyncResult asyncResult)
at Internetlab_Client.DataCenter.Receiver(IAsyncResult ar) in F:\Lab Project\Internetlab Client\DataCenter.vb:line 79
Source >> System
I'd imagine that its because there is nothing to connect to if you haven't started the server yet. So when you start the client first it must be trying to connect before the server is up and running. If it works sometimes then it might be compiling or something and take longer to start so it probably isn't trying to connect until the server is started.
if theres nothing to connect to an exeption is thrown on
TCPClient.Connect(Config.Settings_ServerPath, Config.Settings_ServerPort)
the exeption is then catched, waits for 5secs then tries to connect again, and it does connect, because the exeption is thrown in the datareceiver, so it was connected, and tried to receive something
what can the problem be?!!!
Quote:
Public Sub Connecting()
Try
Trace.Write("Connecting to server ... ")
ClientStatus = Status.Connecting
TCPClient.Connect(Config.Settings_ServerPath, Config.Settings_ServerPort)
Trace.WriteLine("Connected")
DataSender("CONNECT|" & Config.Settings_ClientName)
ClientStatus = Status.WaitingOnServer
TCPClient.GetStream.BeginRead(Buffer, 0, BUFFER_SIZE, AddressOf Receiver, Nothing)
Catch
Trace.WriteLine("Disconnected")
ClientStatus = Status.Disconnected
Thread.Sleep(5000)
Connecting()
End Try
End Sub
any one hast any idea?!! i tried whatever i could think of , still having the same prob, i increased the sleeping time of the thread to 15 secs, now it works more than it fails , what can the problem be?
I dont really know anything about the code but give this other forum a try also
http://gotdotnet.com/Community/Messa...oard.aspx?ID=8
it may help