Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

ok, i've been having a lot of problems lataly, with somthing, and try loads of stuff like thread and so on, but still no luck

So i set up a server that need to listen for connection, in background if posible so i can still have a form visible, but i wandta start and stop button on the form that will start/stop the server, can some one help me out?

I've tryed thread as i said befor, but there is the stop/start problem agen :confused: , same goes for services

here is what i have:

 

'Setup server
   Public ApacheMon_Server_thread As New System.Threading.Thread(AddressOf Server)
   Dim port As Int32 = sApache_server_port
   Public ApacheMon_Server As New TcpListener(port)
   Dim bytes(1024) As [byte]
   Dim data As [string] = Nothing
   Dim client As TcpClient
   Public Sub Server()
       ApacheMon_Server.Start()
       client = ApacheMon_Server.AcceptTcpClient()
       'Connection is made
       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)
           If ([string].Format(data)).ToLower = sApache_server_user.ToLower & ":" & sApache_server_pass.ToLower & "@" & "start" Then
               Retval = Shell(sApache_dir + "/bin/apache.exe -k start -n """ & sApache_service & """ ", AppWinStyle.Hide)
               sRetdate = "[" & Date.Now.Hour & ":" & Date.Now.Minute & ":" & Date.Now.Second & "]The remote Apache server has started."
           ElseIf ([string].Format(data)).ToLower = sApache_server_user.ToLower & ":" & sApache_server_pass.ToLower & "@" & "restart" Then
               Retval = Shell(sApache_dir + "/bin/apache.exe -k restart -n """ & sApache_service & """ ", AppWinStyle.Hide)
               sRetdate = "[" & Date.Now.Hour & ":" & Date.Now.Minute & ":" & Date.Now.Second & "]The remote Apache server has restarted."
           ElseIf ([string].Format(data)).ToLower = sApache_server_user.ToLower & ":" & sApache_server_pass.ToLower & "@" & "stop" Then
               Retval = Shell(sApache_dir + "/bin/apache.exe -k stop -n """ & sApache_service & """ ", AppWinStyle.Hide)
               sRetdate = "[" & Date.Now.Hour & ":" & Date.Now.Minute & ":" & Date.Now.Second & "]The remote Apache server has stopped."

           Else
               sRetdate = "[" & Date.Now.Hour & ":" & Date.Now.Minute & ":" & Date.Now.Second & "]Wrong username and/or password"
           End If
           Dim msg As [byte]() = System.Text.Encoding.ASCII.GetBytes(sRetdate)
           stream.Write(msg, 0, msg.Length)
           client.Close()
           Exit While
       End While
   End Sub

 

The problem whit this is, that it will end the program once it is done, or if i remove the Exit While, it will well stop resonding!

 

any help would be greatly apriciated!

Edited by jorge
Posted
Should the Read function be in the loop because otherwise you're just processing the same thing over and over?
.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
The function accepts one connection, reads data then runs through one piece of information, closes the socket and crashes
.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?

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...