WHats wrong(tcplisten)

jorge

Well-known member
Joined
Jul 13, 2003
Messages
239
Location
Belgium
problem with tcplisten

Ok here is what wrong,
I can send 1 command,
But when it is done processing it, the server termniates,
But id want it to keep listening for more commands

Thanx in advance

[VB]
Public Sub remote()
Buffer for reading data
Dim bytes(1024) As [Byte]
Dim data As [String] = Nothing
set up server
Dim port As Int32 = 99
Dim server As New TcpListener(port)
server.Start()
While True
Wait for a connection...
Dim client As TcpClient = 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 = "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 = "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 = "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 = "error"
End If
Dim msg As [Byte]() = System.Text.Encoding.ASCII.GetBytes(sRetdate)
stream.Write(msg, 0, msg.Length)
client.Close()
Call remote()
Exit Sub
End While
End While
End Sub
[/VB]
 
Last edited by a moderator:
Back
Top