|
-
Oct 14th, 2003, 02:39 PM
#1
Thread Starter
Addicted Member
why does this happen ?!!? ( added some code, plz take a look )
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?
Last edited by persianboy; Oct 14th, 2003 at 02:51 PM.
-
Oct 14th, 2003, 02:46 PM
#2
Frenzied Member
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Oct 14th, 2003, 02:48 PM
#3
Thread Starter
Addicted Member
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
-
Oct 14th, 2003, 03:06 PM
#4
What is the exception message and stack trace?
-
Oct 14th, 2003, 03:12 PM
#5
Thread Starter
Addicted Member
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
-
Oct 14th, 2003, 03:24 PM
#6
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.
-
Oct 14th, 2003, 03:30 PM
#7
Thread Starter
Addicted Member
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?!!!
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
-
Oct 15th, 2003, 12:15 PM
#8
Thread Starter
Addicted Member
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?
-
Oct 15th, 2003, 02:04 PM
#9
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
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|