jorge Posted September 23, 2003 Posted September 23, 2003 (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 September 23, 2003 by jorge Quote Jorge - http://www.blackdot.be/?page=apache.htm
AndreRyan Posted September 23, 2003 Posted September 23, 2003 Should the Read function be in the loop because otherwise you're just processing the same thing over and over? 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 September 23, 2003 Author Posted September 23, 2003 Don't realy know, got most of it from msdn, and i have no id what a loop is :confused: Quote Jorge - http://www.blackdot.be/?page=apache.htm
jorge Posted September 24, 2003 Author Posted September 24, 2003 I do know what it is suposed to do: Start to listen on port xx Wait for a connection, if it get a connection, Read the data that was send, if the date = x then do z en when it done send a respons and returen to wait for a new connection Quote Jorge - http://www.blackdot.be/?page=apache.htm
AndreRyan Posted September 25, 2003 Posted September 25, 2003 The function accepts one connection, reads data then runs through one piece of information, closes the socket and crashes 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 September 25, 2003 Author Posted September 25, 2003 yes, that about it lol, So how can i stop it from crasing whne it done and then go back and listen for a new connection? 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.