Question socket programming

rover886

New member
Joined
Oct 15, 2011
Messages
1
Programming Experience
1-3
hi to all i m developing an windows based application called "Remote Process Explorer" in which i am using socket programming to get process from client machine...but i am facing problem...that is how to know server application is requesting for processes information to client socket because my app. "Remote Process Explorer" is also send message,block an website etc on client machine.

so that how can i know that server socket want process information from client socket..i have try following code...

Imports System.Net.Sockets
Imports System.Text

Public Class Form1
    Dim clientSocket As New System.Net.Sockets.TcpClient()
    Dim serverStream As NetworkStream
    Dim buffSize As Integer
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            clientSocket.Connect("127.0.0.1", 7886)
        Catch ex As Exception
        End Try
        If (clientSocket.Connected = False) Then
            Dim ctThread As Threading.Thread = New Threading.Thread(AddressOf doserversearch)
            ctThread.Start()
        End If
        server_listen.Enabled = True
    End Sub

    Private Sub server_listen_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles server_listen.Tick
        If (clientSocket.Connected = True) Then
            Try
                Dim inStream(10024) As Byte
                serverStream = clientSocket.GetStream()
                buffSize = clientSocket.ReceiveBufferSize
                serverStream.Read(inStream, 0, buffSize)
                Dim returndata As String
                returndata = System.Text.Encoding.ASCII.GetString(inStream)
                MsgBox(returndata.Equals("getprocess").ToString)
      'look at here
                If (returndata = "getprocess") Then
                    Dim ps As Process
                    server_listen.Stop()
                    For Each ps In Process.GetProcesses
                        Try
                            Dim outStream As Byte() = System.Text.Encoding.ASCII.GetBytes(ps.ProcessName.ToString + "|" + ps.MainModule.ModuleName + "|" + ps.MainModule.FileVersionInfo.FileDescription.ToString + "|" + ps.Id.ToString + "|" + ps.MainWindowTitle + "^")
                            '+ "|" + ps(i).ProcessName.ToString + "|" + ps(i).MainModule.FileVersionInfo.FileDescription.ToString + "|")
                            serverStream.Write(outStream, 0, outStream.Length)
                            serverStream.Flush()
                            outStream = Nothing
                            Threading.Thread.Sleep(200)
                            'buffSize = clientSocket.ReceiveBufferSize
                            'serverStream.Read(inStream, 0, buffSize)
                            'Dim returndata As String = System.Text.Encoding.ASCII.GetString(inStream)
                        Catch
                        End Try
                    Next
                End If

            Catch ex As Exception
            Finally
                serverStream = clientSocket.GetStream()
                Dim outStream1 As Byte() = System.Text.Encoding.ASCII.GetBytes("end|")
                serverStream.Write(outStream1, 0, outStream1.Length)
                serverStream.Flush()

            End Try
        End If
    End Sub

    Public Sub doserversearch()
        While (clientSocket.Connected = False)
            Try
                clientSocket.Connect("127.0.0.1", 7886)
                '  Threading.Thread.CurrentThread.Abort()
                server_listen.Enabled = True
            Catch ex As Exception
                '  server_listen.Enabled = True
            End Try
        End While
    End Sub
End Class





the above code does not have any error but if you put an breakpoint at tick event and execute an program along with server socket you come to know that...in tick event

1.i m checking weather client socket is connected or not if yes..
2.i am reading data on server stream by using serverStream.Read(inStream, 0, buffSize) //data which is send by server then...
3.whatever data is read by above code is put into inStream byte array veriable which is encodes and assing to string variable returndata then...
4.next HERE I M FACING PROBLEM in if i m checking data in returndata variable to string "getprocess" (getprocess is the string which is send by server socket.)

PROBLEM IS WHEN I PUT BREAKPOINT I COME TO KNOW THAT..

returndata variable have value "getprocess" which is similar to condition but still it not go to if statement it directly go to end if...

plz help me

I AM ATTACHING THE PROJECT
 

Attachments

  • Project RPE.zip
    37 KB · Views: 19
Last edited by a moderator:
Back
Top