通过SuperSocket发送消息

时间:2014-10-29 14:52:47

标签: c# websocket

我正在使用SuperWebSocket库来处理websockets。我的应用正在为连接的客户端发送消息。如何将数据发送到另一个处理websockets的服务器?

using SuperSocket.SocketBase;
using System;
using SuperSocket.SocketBase.Protocol;

namespace SuperSocket_Test
{
    internal class Program
    {
        static void Main(string[] args)
        {
            var appServer = new AppServer();
            appServer.Setup(123); //binding to 123 port
            appServer.Start();
            Console.WriteLine("The server started successfully, press key 'q' to stop it!");

            appServer.NewRequestReceived += new RequestHandler<AppSession, StringRequestInfo>(appServer_NewRequestReceived);


            while (Console.ReadKey().KeyChar != 'q')
            {
                Console.WriteLine();                
            }
            appServer.Stop();

            Console.WriteLine("The server was stopped!");
            Console.ReadKey();
        } 

        static void appServer_NewRequestReceived(AppSession session, StringRequestInfo requestInfo)
        {           
            session.Send(requestInfo.Body);            
        }
    }
}

1 个答案:

答案 0 :(得分:2)

SuperSocket - 它只是服务器端的lib。对于客户端,您应该使用Websocket4net