/// <summary> /// 创建一个WebSocket连接客户端 /// </summary> /// <param name="host">主机名称</param> /// <param name="origin">发起源地址</param> /// <param name="protocols">使用协议</param> /// <param name="sessionFactory">会话工厂,你可以从WebSocketSessionBase继承,实现自己的会话处理</param> public WebSocketClient(string host, string origin, string protocols, IWebSocketClientSessionFactory sessionFactory) { protocol = new WebSocketProtocol(); this.Host = host; this.Origin = origin; this.Protocols = protocols; this.sessionFactory = sessionFactory; }
public CommandClient(string ipAddress, int port, string host, string protocol, IWebSocketClientSessionFactory sessionFactory, ICommandParser commandParser) { logger = LoggerManager.GetLogger(String.Format("CommandClient_{0}_{1}", ipAddress, port)); SessionCommandParser = commandParser; IsConnecting = false; IP = ipAddress; Port = port; RequestTimeout = TimeSpan.FromMinutes(2); MaxRetryCount = 3; IsAync = true; Session = new CommandSession(); Session.CommandParser = commandParser; IsConnected = false; CommandAliveTime = TimeSpan.FromMinutes(2); CommandList = new List <ICommand>(); CommandList.Add(new SetCommandParserResponse()); CommandParser = new List <ICommandParser>() { new WSCommandType(), new WSBinaryCommandType() }; client = new WebSocketClient(host, "", protocol, sessionFactory); client.Connected += new EventHandler <WebSocketConnectedEventArgs>(ClientConnected); client.Closed += new EventHandler(ClientClosed); client.MessageReceived += new EventHandler <MessageReceivedEventArgs>(MessageReceived); }
public CommandClient(string ipAddress, int port, string host, string protocol, IWebSocketClientSessionFactory sessionFactory) : this(ipAddress, port, host, protocol, sessionFactory, new WSBinaryCommandType()) { }