Still have problems TCPlisnet

jorge

Well-known member
Joined
Jul 13, 2003
Messages
239
Location
Belgium
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 :confused: , 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:
Should the Read function be in the loop because otherwise youre just processing the same thing over and over?
 
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
 
The function accepts one connection, reads data then runs through one piece of information, closes the socket and crashes
 
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?
 

Similar threads

S
Replies
0
Views
148
Sivakumar282000
S
I
Replies
0
Views
156
Innovators World Wide
I
Back
Top