Results 1 to 9 of 9

Thread: why does this happen ?!!? ( added some code, plz take a look )

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Posts
    227

    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.

  2. #2
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    software gremlins.
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Posts
    227
    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

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    What is the exception message and stack trace?

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Posts
    227
    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

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Posts
    227
    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

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Posts
    227
    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?

  9. #9
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    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
  •  



Click Here to Expand Forum to Full Width