Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
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!

[EDIT]

here is the Server
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

the Clinet :
<pre lang="msil">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

Posted
Updated 30-Apr-11 19:34pm
v5
Comments
[no name] 29-Apr-11 10:33am    
Please clarify what you mean by "control client"
Manfred Rudolf Bihy 29-Apr-11 10:34am    
"how can I control the client from the server ..."
If you'd explain what you're trying to control maybe we could give you some tips on how to achieve your goal(s).
Please add more detail as to what exactly you want to do.

Thanks for your cooperation!
hudawk 29-Apr-11 11:24am    
Mark and Manfred what i ment by contrling "if i have 2 media player one as clinet and other as server and i broadcast a video from the server to clinet iwant to be able to stop,mute,play....etc the video in clinet

Hi,
there are plenty of ways in implementing a client/server applications. The most basic ones are described fully in the internet, so you can search for the appropriate implementation. Check the following article: http://www.switchonthecode.com/tutorials/csharp-tutorial-simple-threaded-tcp-server[^]
Regards
 
Share this answer
 
Comments
[no name] 29-Apr-11 10:35am    
I don't believe the OP was asking how to create a client/server application, but rather how to do things on the client from the server.
Ciumac Sergiu 29-Apr-11 10:57am    
There is no way of controlling the client from the server (it doesn't make sense), thus I've inferred the inverse relationship, which the OP was most probably thinking of.
Sergey Alexandrovich Kryukov 29-Apr-11 14:28pm    
I up-vote this answer by my 4.
(Hudawk, did you vote "1"? If so, it's not fair: the answer was based on so little information.)
Sergiu (do I use correct name? it looks like your given name, is it correct?), speaking quite formally, you're right -- that would not be a client-server. But you did not explained it in your answer -- your behaved the way as if you ignored the problem.

Even though the strict term "client-server" is not applicable here, the problem itself makes sense and it is very important. I appreciate OP raised it.
Please see my answer.

@Hudawk, your example of two players is still not clear. What you want to control in client, on what events and why? Why the client cannot stop/mute/play/ of the user's command? If you explain it, preferable with clear use cases, we can discuss some details of the architecture.
--SA
Ciumac Sergiu 29-Apr-11 14:45pm    
Hi SAKryukov,
indeed I didn't go into much details as in the answer you provided, but speaking frankly I do have doubts that inversion of control in a client-server application is a good idea (moreover based on raw sockets, OP will have to implement his own communication protocol over TCP or UDP, in order to achieve this behavior, which is not a trivial task). But the thing that is really more important about this scenario is that, it breaks the concept of a client server app (for the sake of theory it can be done, but I doubt that the client will be happy in this kind of a web service that takes control of your machine :) ).
Regards
Sergey Alexandrovich Kryukov 29-Apr-11 15:08pm    
You never know. I've done several networking and/or Windows Service works where client-service (without inversion of control) would be nearly useless. In certain cases, inversion of control goes almost straight from requirements and is not a matter of architectural options. If you always worked with client-server it does not mean everything else can not exist. Moreover "inversion of control in a client-server application" is oxymoron if you use strict terms: of course is "it breaks the concept of a client server app", you're absolutely right.

The simple thing is: you're not discussing client-server anymore.

I'm not sure OP request is adequate, though, we just don't know yet. "His own communication protocol" is not scary: it can be just the types(s) of the object to be serialized or simply a Data Contract and/or Service Contract. In this sense people do their "own" application protocol even without understanding it's their "own". Not such a bid deal.

Best,
--SA
Strictly speaking, as soon as you say "control client from server", all this immediately goes beyond the client-server paradigm, at least in the narrow sense of this turn. I really appreciate it come to this idea as the "pure" client-server architecture is very limiting or entailing (always ineffective) polling for many applications.

It is related to the idea of inversion of control, see http://en.wikipedia.org/wiki/Inversion_of_control[^]. Please also see the very useful references on the bottom of this document, such as Observer pattern (http://en.wikipedia.org/wiki/Observer_pattern[^]), Pulisher/Subscriber (http://en.wikipedia.org/wiki/Publish/subscribe[^]) and more.

As you don't share what kind of control and work flow you're thinking of, I can only suggest you some ideas from my past answer on a similar topic:
Multple clients from same port Number[^].

—SA
 
Share this answer
 
Comments
hudawk 30-Apr-11 12:10pm    
i will put the code for broadcasting
As i understand, the closest to the definition to control client from server is bot-server/bot-client architecture sometimes called C&C (command and control). I guess, there are not so many people around that are ready to explain this topic in detail (though it is interesting one).
Sergey Chepurin.
 
Share this answer
 
Comments
hudawk 30-Apr-11 14:33pm    
Can you tell me how to start what i should searching for because iam really confused
thanks
Sergey Chepurin 30-Apr-11 15:40pm    
So i am right? But this is a question for hacking related forums. I am interested in this problem simply because it can be helpful in understanding of networking issues (hardcore networking). There are many things that were discovered and developed by hackers and later used in general programming. As usual in such cases, i can only advice to start from Wikipedia.
Sergey Chepurin.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900