server won't accept client?!?

jorge

Junior Contributor
Joined
Jul 13, 2003
Messages
239
Location
Belgium
Ok i have a pice of code, but when a client connect the server won't do anyhting. is there somthing wrong with my code?

Thanx in advance
Visual Basic:
    Sub server_wait()
        Do While server_process.ThreadState = Threading.ThreadState.Running
            If client Is server_listener.AcceptTcpClient Then
                client = server_listener.AcceptTcpClient()
                data = Nothing
                Dim stream As NetworkStream = client.GetStream()
                Dim i As Int32
                i = stream.Read(bytes, 0, bytes.Length)
                While (i <> 0)
                    Dim sRetdate As String
                    data = System.Text.Encoding.ASCII.GetString(bytes, 0, i)
                    MsgBox(data)
                    Exit While
                End While
            End If
        Loop
    End Sub
 
yes,
I resteste it afterward with:
Visual Basic:
if server_process.ThreadState = Threading.ThreadState.Running the
msgbox("running")
end if
and i get running.
 
Does your line .... MsgBox(data) ever get raised?


Also, if you place a MessageBox at the last line of your sub will it ever trigger? (maybe replace the "Exit While" with "Exit Sub" for this test)
 
No, my msgbox(data) never show, if i puase my programm the last loction is: If client Is server_listener.AcceptTcpClient Then
and when i press run agen an pause a few second later i'm still there in stead of skipping and retrying.
 
There seems to be a problem with this, you're accepting a client then trying to accept it again once it's been removed from the Pending Que
Visual Basic:
Sub server_wait()
        Dim i As Int32, ReadingBytes(0) As Byte
        Do While server_process.ThreadState = Threading.ThreadState.Running
            If server_listener.Pending Then 'Accept removes the client from the Que
                client = server_listener.AcceptTcpClient()
                data = Nothing
                Dim stream As NetworkStream = client.GetStream()
                Do While (stream.DataAvaliable)
                    ReadingBytes(ReadingBytes.GetUpperBound(0)) = Convert.ToByte(stream.ReadByte()) 'Read next byte
                    Redim Preserve ReadingBytes(ReadingBytes.GetUpperBound(0) + 1) 'Enlarge Array for next entry
                Loop
                data = System.Text.Encoding.ASCII.GetString(ReadingBytes, 0, ReadingBytes.GetUpperBound(0) - 1)
                 MsgBox(data)
                 Redim ReadingBytes(0) 'Reset Array
            End If
        Loop
    End Sub
 
Last edited:
Ok, i have one more question
I'm running the server in a thread, so the gui can sta active. Its a trayicon with start/stop and exit in it contextmenu, but i when i click on any of the menu item it does nothing, i need to click on the trayicon a 2nd time befor it executes it, is that normal? is there a fix?
I've attached the code.
//edit: sry forgot to remove the exe file, so i had to reupload
 

Attachments

Back
Top