Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • Moderators
Posted

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)

Visit...Bassic Software
Posted (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 by AndreRyan
.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?
Posted

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

apachemon-19-10-03(new server code).zip

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...