Hi!
I have created two applications communicating over sockets, one being the client and the other being a server. I want someone to tell me how I can control the client from the server.

Please tell me where and how to start.

Thanks in advance!


this is server code

Imports System.Net.Sockets
 
Imports System.Threading
Imports System.Windows.Forms
Imports System.IO
 

Public Class broadcast
 

 
    Private conn As Socket
    Private readthread As Thread
    Private socketstream As NetworkStream
    Private writer As BinaryWriter
    Dim c As String
 
    Private reader As BinaryReader
    Public Sub New()
        MyBase.New()
 

 
        readthread = New Thread(AddressOf RunServer)
        readthread.Start()
 

 
    End Sub
 
    Public Sub RunServer()
        Dim listener As New TcpListener(5234)
        Dim counter As Integer = 1
        Try
 
            listener.Start()
            While True
 
                Dim b As String
 
                b = "C:\Users\Public\Videos\Sample Videos\Wildlife.wmv" '

                conn = listener.AcceptSocket
                socketstream = New NetworkStream(conn)
                writer = New BinaryWriter(socketstream)
                reader = New BinaryReader(socketstream)
 
                Dim theReplay As String = ""
                Select Case c 'here i need to control the clinet play,pause,mute....etc but  this select statment did'nt worked 
                    Case "play"
                        frmMain.AxWindowsMediaPlayer1.Ctlcontrols.play()
 

 
                End Select
                Try
 

 
                    writer.Write(b)
 
                    writer.Write(c)
 

                    'Catch inputputputexception As IOException
                Catch inputputputexception As Exception
                    MessageBox.Show("Clinet application closing")
                Finally
 
                    writer.Close()
                    reader.Close()
                    socketstream.Close()
                    conn.Close()
                    counter += 1
 
                End Try
 
            End While
 
        Catch inpitoutputException As IOException
            MessageBox.Show("Server application Closing")
 
        End Try
    End Sub
 

End Class

this is clinet code

Imports System.Net.Sockets
Imports System.Windows.Forms
Imports System.IO
Imports System.Threading
Public Class recieve
 
    Private output As NetworkStream
    Private reader As BinaryReader
    Private writer As BinaryWriter
    Private message As String = ""
    Private readthred As Thread
    Public Sub New()
        MyBase.New()
 
        readthred = New Thread(AddressOf runClinet)
       readthred.Start()
 
    End Sub
 
    Public Sub runClinet()
        Dim clinet As TcpClient
        Try
            clinet = New TcpClient()
            clinet.Connect("127.0.0.1", 5234)
            output = clinet.GetStream()
            writer = New BinaryWriter(output)
            reader = New BinaryReader(output)
            Try
                               Dim r As String
 
                message = reader.ReadString' Here must recive the video and action of the controls
                               frmMain.AxWindowsMediaPlayer1.URL = message
                frmMain.Playlist.Items.Add(message)
                MessageBox.Show(message & ":" & frmMain.Playlist.Items.Count)
                       Catch inputoutputException As IOException
                MessageBox.Show("Clinet application Closing")
            Finally
                writer.Close()
                reader.Close()
                output.Close()
                clinet.Close()
            End Try
            
        Catch inputoutputException As IOException
            MessageBox.Show("Clinet application Close")
        End Try
    End Sub
End Class

I did a similar thing a while ago.
What I did was hardcode a bunch of macro-type strings into the client, for example: "#PLAY#", "#STOP#" or "#PAUSE#".
By sending the same string from the server and comparing the hardcoded string against the incoming string you can then call any other function to perform a specific task tied to that macro-string.

And also, if you need to send a file for the server to play, you need to send it as a byte array. Not a string.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.