jorge Posted October 17, 2003 Posted October 17, 2003 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 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 Quote Jorge - http://www.blackdot.be/?page=apache.htm
Moderators Robby Posted October 17, 2003 Moderators Posted October 17, 2003 Check the server_process.ThreadState before going into the loop and see what it returns. Quote Visit...Bassic Software
jorge Posted October 17, 2003 Author Posted October 17, 2003 Ok it give 0, so it is running. Quote Jorge - http://www.blackdot.be/?page=apache.htm
Moderators Robby Posted October 17, 2003 Moderators Posted October 17, 2003 I don't have .NET right now but are you sure that 0 (zero) is Running Quote Visit...Bassic Software
jorge Posted October 17, 2003 Author Posted October 17, 2003 yes, I resteste it afterward with: if server_process.ThreadState = Threading.ThreadState.Running the msgbox("running") end if and i get running. Quote Jorge - http://www.blackdot.be/?page=apache.htm
Moderators Robby Posted October 17, 2003 Moderators Posted October 17, 2003 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) Quote Visit...Bassic Software
jorge Posted October 18, 2003 Author Posted October 18, 2003 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. Quote Jorge - http://www.blackdot.be/?page=apache.htm
AndreRyan Posted October 19, 2003 Posted October 19, 2003 (edited) 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 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 Edited October 19, 2003 by AndreRyan Quote .Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
jorge Posted October 19, 2003 Author Posted October 19, 2003 (edited) Thanx, it work like a charm Edited October 19, 2003 by jorge Quote Jorge - http://www.blackdot.be/?page=apache.htm
jorge Posted October 19, 2003 Author Posted October 19, 2003 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 reuploadapachemon-19-10-03(new server code).zip Quote Jorge - http://www.blackdot.be/?page=apache.htm
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.