【发布时间】:2015-05-20 06:51:29
【问题描述】:
我正在使用 WebSockets 并尝试为我的服务器客户端设置代码库。我知道如何从客户端向服务器发送消息,也知道如何从服务器端监听这些消息。
但是,如何将消息发送回客户端?
// here is the _clientSocket that I accepted
_clientSocket = _serverSocket.Accept();
int received = _clientSocket.Receive(_buffer, 0, _buffer.Length,
SocketFlags.None);
// here is the message I got from the client
string receivedMsg = Encoding.ASCII.GetString(_buffer);
if (receivedMsg == "1")
//TO DO: send back to client "This is a test message from server".
【问题讨论】:
-
你知道有一个叫 SignalR 的框架吗? :P
-
SignalR 可以在没有 ASP.NET 的情况下使用
-
WebSockets 已经得到很好的支持,使用有限的可扩展性的 polyfill 是没有意义的。