public TcpMeetingBridgeAgentListener(MeetingAgentType type, IMeetingBridge meetingBridge, int port) { this.type = type; this.meetingBridge = meetingBridge; this.port = port; tcpListener = new TcpSocketServer(8000); }
public void Close() { if (tcpListener == null) return; tcpListener.OnNewConnection -= OnNewConnection; tcpListener.OnExceptionThrown -= OnSocketServerExceptionThrown; tcpListener.Close(); tcpListener = null; }
/// <summary> /// 监听本地ip /// </summary> /// <param name="port">监听的端口号</param> public void StartServer(int port) { var config = new TcpSocketServerConfiguration(); config.FrameBuilder = new LengthPrefixedFrameBuilder(); _server = new TcpSocketServer(port, config); _server.ClientConnected += server_ClientConnected; _server.ClientDisconnected += server_ClientDisconnected; _server.ClientDataReceived += server_ClientDataReceived; _server.Listen(); }
/// <summary> /// 抽牌 /// </summary> /// <param name="GameId"></param> /// <param name="IsHost"></param> /// <param name="CardCount"></param> /// <returns></returns> public static List <string> DrawCard(string GameId, bool IsHost, int CardCount) { string requestInfo = ServerResponse.RequestType.抽牌.GetHashCode().ToString("D3") + GameId + (IsHost ? CardUtility.strTrue : CardUtility.strFalse) + CardCount.ToString("D1"); List <string> CardList = new List <string>(); foreach (var card in TcpSocketServer.Request(requestInfo, TcpSocketServer.strIP).Split(CardUtility.strSplitArrayMark.ToArray())) { CardList.Add(card); } return(CardList); }
void OnStart(TcpSocketServer server) { ThreadCalls(() => { cbbSPIP.Enabled = false; nudSPPort.Enabled = false; nudSPCount.Enabled = false; btnSPStart.Enabled = false; btnSPStop.Enabled = true; PrintLog("启动SP网关服务成功!"); }); }
void OnStart(TcpSocketServer server) { ThreadCalls(() => { cbbSMSCIP.Enabled = false; nudSMSCCount.Enabled = false; nudSMSCPort.Enabled = false; btnSMSCStart.Enabled = false; btnSMSCStop.Enabled = true; PrintLog("启动SMSC网关服务成功!"); }); }
private static void StartServer() { var config = new TcpSocketServerConfiguration(); //config.UseSsl = true; //config.SslServerCertificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(@"D:\\Cowboy.pfx", "Cowboy"); //config.SslPolicyErrorsBypassed = false; _server = new TcpSocketServer(22222, config); _server.ClientConnected += server_ClientConnected; _server.ClientDisconnected += server_ClientDisconnected; _server.ClientDataReceived += server_ClientDataReceived; _server.Listen(); }
/// <summary> /// 添加指令 /// </summary> /// <param name="GameId"></param> public static void WriteAction(string GameId, List <string> Action) { string Transform = string.Empty; foreach (var item in Action) { Transform += item + CardUtility.strSplitArrayMark; } Transform = Transform.TrimEnd(CardUtility.strSplitArrayMark.ToCharArray()); string requestInfo = ServerResponse.RequestType.写入行动.GetHashCode().ToString("D3") + GameId + Transform; TcpSocketServer.Request(requestInfo, TcpSocketServer.strIP); }
/// <summary> /// 是否触发了奥秘 /// </summary> /// <returns></returns> public static string IsSecretHit(string GameId, bool IsFirst, List <string> Actionlst) { string Transform = string.Empty; foreach (var item in Actionlst) { Transform += item + CardUtility.strSplitArrayMark; } Transform = Transform.TrimEnd(CardUtility.strSplitArrayMark.ToCharArray()); string requestInfo = ServerResponse.RequestType.奥秘判定.GetHashCode().ToString("D3") + GameId + (IsFirst ? CardUtility.strTrue : CardUtility.strFalse) + Transform; return(TcpSocketServer.Request(requestInfo, TcpSocketServer.strIP)); }
private static void StartServer() { var config = new TcpSocketServerConfiguration(); //config.UseSsl = true; //config.SslServerCertificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(@"D:\\Cowboy.pfx", "Cowboy"); //config.SslPolicyErrorsBypassed = false; _server = new TcpSocketServer(22222, config); _server.ClientConnected += server_ClientConnected; _server.ClientDisconnected += server_ClientDisconnected; _server.ClientDataReceived += server_ClientDataReceived; _server.Listen(); }
/// <summary> /// 传送套牌 /// </summary> /// <param name="NickName"></param> public static bool SendDeck(string GameId, bool IsHost, List <string> CardDeck) { string info = string.Empty; foreach (var card in CardDeck) { info += card + CardUtility.strSplitArrayMark; } info = info.TrimEnd(CardUtility.strSplitArrayMark.ToCharArray()); string requestInfo = ServerResponse.RequestType.送套牌.GetHashCode().ToString("D3") + GameId + (IsHost ? CardUtility.strTrue : CardUtility.strFalse) + info; return(TcpSocketServer.Request(requestInfo, TcpSocketServer.strIP) == CardUtility.strTrue); }
private void btnSMSCStart_Click(object sender, EventArgs e) { if (cbbSMSCIP.Text == "") { return; } if (tcpSMSCServer == null || !tcpSMSCServer.Listened) { tcpSMSCServer = new TcpSocketServer(cbbSMSCIP.Text, (int)nudSMSCPort.Value); var handler = new SMSCServerHandler(this, tcpSMSCServer); MessageCenter.GetInstance().RegisterSMSC(handler); tcpSMSCServer.Listen((int)nudSMSCCount.Value); } }
public void Start() { _socketServer = new TcpSocketServer(_port) { HandleRecMsg = (a, b, bytes) => { ResponseModel response = new ResponseModel(); try { var requestModel = bytes.ToString(Encoding.UTF8).ToObject <RequestModel>(); if (!_serviceHandle.ContainsKey(requestModel.ServiceName)) { throw new Exception("未找到该服务"); } var serviceType = _serviceHandle[requestModel.ServiceName]; var service = Activator.CreateInstance(serviceType); var method = serviceType.GetMethod(requestModel.MethodName); if (method == null) { throw new Exception("未找到该方法"); } var res = method.Invoke(service, requestModel.Paramters.ToArray()); response.Success = true; response.Data = res.ToJson(); response.Msg = "请求成功"; } catch (Exception ex) { response.Success = false; response.Msg = ExceptionHelper.GetExceptionAllMsg(ex); } finally { b.Send(response.ToJson().ToBytes(Encoding.UTF8)); b.Close(); //Task.Run(() => //{ // b.Close(); //}); } }, RecLength = 1024 * 1024, HandleException = this.HandleException == null ? null : new Action <Exception>(this.HandleException) }; _socketServer.StartServer(); }
public SPServerHandler(VirtualGetway form, TcpSocketServer tcpServer) { this.form = form; this.tcpServer = tcpServer; this.spClientPool = new List <SPClient>(); sequeueDict = new Dictionary <string, string>(); this.OnCreate(); tcpServer.OnConnected += this.OnConnected; tcpServer.OnDisconnected += this.OnDisconnected; tcpServer.OnStart += this.OnStart; tcpServer.OnStop += this.OnStop; tcpServer.OnRead += this.OnRead; tcpServer.OnSend += this.OnSend; tcpServer.OnException += this.OnException; }
public void Start() { if (IsListening) { return; } if (this.ListenedEndPoint.Address.Equals(IPAddress.None) || this.ListenedEndPoint.Address.Equals(IPAddress.IPv6None)) { return; } try { var configuration = new TcpSocketServerConfiguration() { ConnectTimeout = this.TransportConfiguration.ConnectTimeout, ReceiveBufferSize = this.TransportConfiguration.ReceiveBufferSize, SendBufferSize = this.TransportConfiguration.SendBufferSize, ReceiveTimeout = this.TransportConfiguration.ReceiveTimeout, SendTimeout = this.TransportConfiguration.SendTimeout, NoDelay = this.TransportConfiguration.NoDelay, LingerState = this.TransportConfiguration.LingerState, KeepAlive = this.TransportConfiguration.KeepAlive, KeepAliveInterval = this.TransportConfiguration.KeepAliveInterval, ReuseAddress = this.TransportConfiguration.ReuseAddress, }; _server = new TcpSocketServer(this.ListenedEndPoint, configuration); _server.ClientConnected += OnClientConnected; _server.ClientDisconnected += OnClientDisconnected; _server.ClientDataReceived += OnClientDataReceived; _log.DebugFormat("TCP server is listening to [{0}].", this.ListenedEndPoint); _server.Listen(); } catch { _server.Shutdown(); _server.ClientConnected -= OnClientConnected; _server.ClientDisconnected -= OnClientDisconnected; _server.ClientDataReceived -= OnClientDataReceived; _server = null; throw; } }
private void localTcp() { SocketParameter socketParameter = new SocketParameter(StaticUtil.PRINT_ADDRESS, StaticUtil.LOCAL_PORT); localTcpSocketServer = TcpSocketServer.getInstance(); localTcpSocketServer.UIDelegateUIMessage += updateMsg; string result = localTcpSocketServer.start(socketParameter); if ("SUCCESS".Equals(result)) { this.txt_print_log.AppendText("本地TCP打印服务已启动...\r\n"); } else { this.txt_print_log.AppendText("本地TCP打印服务启动异常:" + result + "\r\n"); } }
//public static TcpHostServer Create(IPEndPoint ep) //{ // return Create(ep.Address.ToIPv4String(), ep.Port); //} public static TcpHostServer Create(IPEndPoint ep) { var channelConfig = new TcpChannelConfig(); channelConfig.Address = ep;// ip;// "0.0.0.0"; //channelConfig.Port = port; #if !UNITY_5_3_OR_NEWER channelConfig.UseLibuv = true; #endif var listener = new TcpHostServer(); var server = new TcpSocketServer(); if (!server.Start(channelConfig, listener)) { return(null); } return(listener); }
public void Listening() { if (string.IsNullOrEmpty(Ip) || !Port.HasValue) { LogHelper.Logger.Error("ip,port is not available !!!"); throw new Exception("ip,port is not available !!!"); } var config = new TcpSocketServerConfiguration(); Server = new TcpSocketServer(IPAddress.Parse(Ip), Port.Value, config); Server.ClientConnected += ClientConnected; Server.ClientDisconnected += ClientDisconnected; Server.ClientDataReceived += ClientDataReceived; Server.Listen(); LogHelper.Logger.Information("Server Listening..."); }
public RpcAgent(PluginManager pluginMgr) : base(pluginMgr) { handler = new RpcHandler(); var config = new TcpSocketServerConfiguration(); config.AllowNatTraversal = false; server = new TcpSocketServer(Settings.Default.Port, config); server.ClientConnected += OnClientConnected; server.ClientDisconnected += OnClientDisconnected; server.ClientDataReceived += OnClientDataReceived; server.Listen(); Console.WriteLine(string.Format("Rpc agent is running on port {0}.", Settings.Default.Port)); }
private static void Start() { try { ITcpSocketServer tcpSocketServer = new TcpSocketServer(new ChatRoomService(), Port); TcpListener tcpListener = tcpSocketServer.StartListening(); while (true) { TcpClient client = tcpSocketServer.WaitForConnection(tcpListener); Task.Run(() => Process(tcpSocketServer, client)); } } catch (Exception ex) { PrintException(ex); Console.ReadKey(); } }
private static void StartServer() { var config = new TcpSocketServerConfiguration(); //config.UseSsl = true; //config.SslServerCertificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(@"D:\\Cowboy.pfx", "Cowboy"); //config.SslPolicyErrorsBypassed = false; //config.FrameBuilder = new FixedLengthFrameBuilder(20000); //config.FrameBuilder = new RawBufferFrameBuilder(); //config.FrameBuilder = new LineBasedFrameBuilder(); //config.FrameBuilder = new LengthPrefixedFrameBuilder(); //config.FrameBuilder = new LengthFieldBasedFrameBuilder(); _server = new TcpSocketServer(22222, config); _server.ClientConnected += server_ClientConnected; _server.ClientDisconnected += server_ClientDisconnected; _server.ClientDataReceived += server_ClientDataReceived; _server.Listen(); }
static void Main(string[] args) { var app = new PixonicServerPlugin("PixonicApp"); var transport = new TcpSocketServer(IPAddress.Any, 7); app.InitTransports(new List <IServerTransport> { transport }); app.RegisterReceiveCommand(transport, new MessageRequest()); app.RegisterReceiveCommand(transport, new JoinRequest()); app.RegisterReceiveCommand(transport, new LeaveRequest()); transport.OnConnected += (sender, eventArgs) => { Console.WriteLine("Client connected, waiting for JoinCommand to join room"); }; Console.WriteLine("TCP Server is listening on port 7, use any suitable client with Quaternion protocol realized to make connection"); Console.WriteLine("Have fun!"); Done.WaitOne(); }
public OperationState Load(IServerPlugin plugin) { try { var tcpServer = new TcpSocketServer(); plugin.InitTransports(new List <IServerTransport> { tcpServer }); } catch (Exception ex) { return(new OperationState { IsSuccessful = false, Details = ex.ToString() }); } return(new OperationState { IsSuccessful = true }); }
private static void StartServer() { var config = new TcpSocketServerConfiguration(); //config.UseSsl = true; //config.SslServerCertificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(@"D:\\Cowboy.pfx", "Cowboy"); //config.SslPolicyErrorsBypassed = false; //config.FrameBuilder = new FixedLengthFrameBuilder(20000); //config.FrameBuilder = new RawBufferFrameBuilder(); //config.FrameBuilder = new LineBasedFrameBuilder(); //config.FrameBuilder = new LengthPrefixedFrameBuilder(); //config.FrameBuilder = new LengthFieldBasedFrameBuilder(); _server = new TcpSocketServer(22222, config); _server.ClientConnected += server_ClientConnected; _server.ClientDisconnected += server_ClientDisconnected; _server.ClientDataReceived += server_ClientDataReceived; _server.Listen(); }
/// <summary> /// 发送文件 /// </summary> /// <param name="path">文件路径</param> /// <param name="flag">文件类型</param> int SendFile(string sessionKey, TcpSocketServer _server) { if (!File.Exists(this.Message)) { OnMessageEvent("文件不存在"); Logs.Error("文件不存在"); return(FAIRED); } try { using (FileStream fsRead = new FileStream(this.Message, FileMode.OpenOrCreate, FileAccess.Read)) { byte[] buffer = new byte[1024 * 1024 * 3]; int r = fsRead.Read(buffer, 0, buffer.Length); List <byte> list = new List <byte>(); list.Add((byte)this.Type); list.AddRange(buffer); byte[] newBuffer = list.ToArray(); list.Clear(); if (sessionKey.Trim() == "") { _server.Broadcast(newBuffer, 0, r + 1); } else { _server.SendTo(sessionKey, newBuffer, 0, r + 1); } // MessageBox.Show("文件已发送~~"); OnMessageEvent("文件发送成功"); } return(SUCCESS); } catch (Exception ex) { Logs.Error("文件发送失败" + ex); OnMessageEvent("文件发送失败" + ex); throw new FileNotFoundException(); } }
public void Stop() { if (!IsListening) { return; } if (this.ListenedEndPoint.Address.Equals(IPAddress.None) || this.ListenedEndPoint.Address.Equals(IPAddress.IPv6None)) { return; } try { _server.ClientConnected -= OnClientConnected; _server.ClientDisconnected -= OnClientDisconnected; _server.ClientDataReceived -= OnClientDataReceived; _server.Shutdown(); _server = null; } catch { } }
public void Start() { if (IsListening) { return; } if (this.ListenedEndPoint.Address.Equals(IPAddress.None) || this.ListenedEndPoint.Address.Equals(IPAddress.IPv6None)) { return; } try { var configuration = new TcpSocketServerConfiguration() { SendTimeout = TimeSpan.FromSeconds(15), ReceiveTimeout = TimeSpan.Zero, }; _server = new TcpSocketServer(this.ListenedEndPoint, configuration); _server.ClientConnected += OnClientConnected; _server.ClientDisconnected += OnClientDisconnected; _server.ClientDataReceived += OnClientDataReceived; _log.DebugFormat("TCP server is listening to [{0}].", this.ListenedEndPoint); _server.Listen(); } catch { _server.ClientConnected -= OnClientConnected; _server.ClientDisconnected -= OnClientDisconnected; _server.ClientDataReceived -= OnClientDataReceived; _server.Shutdown(); _server = null; throw; } }
/// <summary> /// 开启服务端监听 /// </summary> private static void StartServer() { var config = new TcpSocketServerConfiguration(); #region 配置信息 //config.UseSsl = true; //config.SslServerCertificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(@"D:\\Cowboy.pfx", "Cowboy"); //config.SslPolicyErrorsBypassed = false; //config.FrameBuilder = new FixedLengthFrameBuilder(20000); //config.FrameBuilder = new RawBufferFrameBuilder(); //config.FrameBuilder = new LineBasedFrameBuilder(); //config.FrameBuilder = new LengthPrefixedFrameBuilder(); //config.FrameBuilder = new LengthFieldBasedFrameBuilder(); #endregion 配置信息 _server = new TcpSocketServer(int.Parse(System.Configuration.ConfigurationManager.AppSettings["SocketServerHost"].ToString()), config); _server.ClientConnected += server_ClientConnected; _server.ClientDisconnected += server_ClientDisconnected; _server.ClientDataReceived += server_ClientDataReceived; _server.Listen(); }
public abstract void Send(string sessionKey, TcpSocketServer _server);
public void Send(TcpSocketServer server) { server.Broadcast(GetBytes()); }
public Launcher() { var tcp = new TcpSocketServer(); TransportList.Add(tcp); }
/// <summary> /// 确认游戏状态 /// </summary> /// <param name="NickName"></param> public static bool IsGameStart(string GameId) { string requestInfo = ServerResponse.RequestType.游戏启动状态.GetHashCode().ToString("D3") + GameId; return(TcpSocketServer.Request(requestInfo, TcpSocketServer.strIP) == CardUtility.strTrue); }
/// <summary> /// 等待游戏列表 /// </summary> /// <param name="NickName"></param> public static string GetWatiGameList() { string requestInfo = ServerResponse.RequestType.等待游戏列表.GetHashCode().ToString("D3"); return(TcpSocketServer.Request(requestInfo, TcpSocketServer.strIP)); }
/// <summary> /// 加入游戏 /// </summary> /// <param name="GameId"></param> /// <param name="NickName"></param> /// <returns></returns> public static string JoinGame(string GameId, string NickName) { string requestInfo = ServerResponse.RequestType.加入游戏.GetHashCode().ToString("D3") + GameId + NickName; return(TcpSocketServer.Request(requestInfo, TcpSocketServer.strIP)); }
public TcpConnectionListener(IConnectionFactory<TcpSocketClient> connectionFactory, IRegistrator<string, IConnection> registrator) { this.registrator = registrator; this.connectionFactory = connectionFactory; tcpListener = new TcpSocketServer(2048); }