如何从服务器控制客户端 [英] How to control client from server
本文介绍了如何从服务器控制客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨!
我创建了两个通过套接字进行通信的应用程序,一个是客户端,另一个是服务器.我希望有人告诉我如何从服务器控制客户端.
请告诉我从哪里开始以及如何开始.
提前谢谢!
这是服务器
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!
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
推荐答案
有许多方法可以实现客户端/服务器应用程序. Internet上已对最基本的内容进行了全面描述,因此您可以搜索适当的实现.检查以下文章: http://www.switchonthecode.com/tutorials/csharp-tutorial -simple-threaded-tcp-server [ ^ ]
关于
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
严格来说,只要您说从服务器控制客户端",至少在此转义上,这一切立即超出了客户端-服务器范式.我真的很感谢这种想法,因为纯"客户端-服务器体系结构非常局限性或对许多应用程序都要求轮询(总是无效).
它与inversion of control
的概念有关,请参见 http://en.wikipedia.org/wiki/Inversion_of_control [ ^ ].另请参阅本文档底部的非常有用的参考,例如观察者模式( http://en.wikipedia.org/wiki/Observer_pattern [ ^ ]),推送器/订阅者( http://en.wikipedia.org/wiki/Publish/订阅 [ ^ ])等等.
由于您没有分享您正在考虑的控制和工作流程类型,因此我只能根据您过去回答类似主题时提出的一些建议向您提出建议:
来自同一端口号的多个客户端 [
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 ofinversion 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
据我了解,最接近服务器上控制客户端的定义是bot-server/bot-client体系结构有时称为 C& C (命令和控制).我想,周围没有多少人愿意详细解释这个话题(尽管这很有趣).
谢尔盖·吉普林(Sergey Chepurin).
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.
这篇关于如何从服务器控制客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文