ok, ive 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?
Ive tryed thread as i said befor, but there is the stop/start problem agen , same goes for services
here is what i have:
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!
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?
Ive tryed thread as i said befor, but there is the stop/start problem agen , same goes for services
here is what i have:
Code:
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!
Last edited by a moderator: