public GameServer(bool autoConnect, int port, int broadCastPort, string netGroup) { maxPlayer = AppCfg.expose.MaxPlayer; waitConnectTime = AppCfg.expose.WaitConnectTime; maxEnterSceneTime = ServerCfg.MaxEnterSceneTime; host = new TcpHost(); curPlayer = 1; host.SetHost(port, maxPlayer); this.autoConnect = autoConnect; if (autoConnect) { IPHostEntry IpEntry = Dns.GetHostEntry(Dns.GetHostName()); foreach (IPAddress ipa in IpEntry.AddressList) { if (ipa.AddressFamily == AddressFamily.InterNetwork) { localIP = ipa.ToString(); break; } } syncIpConnection = new UdpBase(broadCastPort, "SyncIP_Host", false); broadcastSelfData = Encoding.UTF8.GetBytes(Application.version + "|" + localIP.ToString() + "|" + netGroup); broadcastSelf = true; } gameStatus = GameStatus.WaitConnect; startUpTime = Time.time; Debug.LogWarning("部署服务器成功"); }
public override void Init() { base.Init(); StartJamodSlave(program); MasterTcp = new TcpClient(TcpHost.ToString(), Port); Master = ModbusIpMaster.CreateIp(MasterTcp); }
public NModbusTcpMasterJamodTcpSlaveFixture() { string program = $"TcpSlave {Port}"; StartJamodSlave(program); MasterTcp = new TcpClient(TcpHost.ToString(), Port); Master = ModbusIpMaster.CreateIp(MasterTcp); }
public TcpZkTests() { _tester = new NetTester(); _ipAddress = IPAddress.Parse("127.0.0.1"); _tcphost = new TcpHost(CreateEndPoint(), zkRepository: _repo); _tcphost.AddService <INetTester>(_tester); _tcphost.Open(); }
public void Close() { Debug.LogWarning("关闭服务器"); host.Dispose(); host = null; if (syncIpConnection != null) { syncIpConnection.Dispose(); } }
public FileServer() { this.host = new TcpHost(); this.host.LoadCmdMethod("Config/Cmd.xml"); this.host.Encrypt = EncryptUtils.Encrypt; this.host.Decrypt = EncryptUtils.Decrypt; this.host.ClientConnectedEvent += OnClientConnectedEvent; this.host.ClientClosedEvent += OnClientClosedEvent; this.host.MvcHostServerErrorEvent += OnMvcHostServerErrorEvent; }
private void OnClientConnectedEvent(TcpHost server, Session session) { UserInfo user = new UserInfo() { SessionId = session.Sid, ClientAddress = session.Address }; session[USER_INFO_KEY] = user; }
public NModbusTcpMasterNModbusTcpSlaveFixture() { SlaveTcp = new TcpListener(TcpHost, Port); SlaveTcp.Start(); Slave = ModbusTcpSlave.CreateTcp(SlaveAddress, SlaveTcp); StartSlave(); MasterTcp = new TcpClient(TcpHost.ToString(), Port); Master = ModbusIpMaster.CreateIp(MasterTcp); }
public override void Init() { base.Init(); SlaveTcp = new TcpListener(TcpHost, Port); SlaveTcp.Start(); Slave = ModbusTcpSlave.CreateTcp(SlaveAddress, SlaveTcp); StartSlave(); MasterTcp = new TcpClient(TcpHost.ToString(), Port); Master = ModbusIpMaster.CreateIp(MasterTcp); }
public void Configure(MiNetServer server) { var logger = new Logger(logLevel: LogLevel.Debug); var stats = new Stats(); _levelService = new LevelService(server); _server = new TcpHost(new IPEndPoint(IPAddress.Any, 19137), logger, stats); _server.AddService <ILevelService>(_levelService); _server.Open(); Log.InfoFormat("Dev Tools LevelService Started"); }
static void Main(string[] args) { var logger = new Logger(logLevel: LogLevel.Debug); var stats = new Stats(); var addr = new[] { "127.0.0.1", "8098" }; //defaults if (null != args && args.Length > 0) { var parts = args[0].Split(':'); if (parts.Length > 1) { addr[1] = parts[1]; } addr[0] = parts[0]; } var ip = addr[0]; var port = Convert.ToInt32(addr[1]); var ipEndpoint = new IPEndPoint(IPAddress.Any, port); var useCompression = false; var compressionThreshold = 131072; //128KB var zkRepository = new DemoZkRepository(); var tcphost = new TcpHost(ipEndpoint, logger, stats, zkRepository); tcphost.UseCompression = useCompression; tcphost.CompressionThreshold = compressionThreshold; var simpleContract = new DataContractImpl(); tcphost.AddService <IDataContract>(simpleContract); var complexContract = new ComplexDataContractImpl(); tcphost.AddService <IComplexDataContract>(complexContract); var test = new Test(); tcphost.AddService <ITest>(test); tcphost.Open(); Console.WriteLine("Press Enter to stop the dual host test."); Console.ReadLine(); tcphost.Close(); Console.WriteLine("Press Enter to quit."); Console.ReadLine(); }
private void OnClientClosedEvent(TcpHost server, Session session) { try { UserInfo user = session[USER_INFO_KEY] as UserInfo; SessionUtils.UserInfo = user; var userService = IocUtils.Get <IUserService>(); userService.Logout(); } catch (Exception ex) { LogUtils.Error("【OnClientClosedEvent】", ex); } }
static void Main(string[] args) { var logger = new Logger(logLevel: LogLevel.Debug); var stats = new Stats(); var ip = ConfigurationManager.AppSettings["ip"]; var port = Convert.ToInt32(ConfigurationManager.AppSettings["port"]); var ipEndpoint = new IPEndPoint(IPAddress.Any, port); var useCompression = false; var compressionThreshold = 131072; //128KB var pipeName = "ServiceWireTestHost"; var nphost = new NpHost(pipeName, logger, stats); var tester = new NetTester(); nphost.AddService <INetTester>(tester); var mytester = new MyTester(); nphost.UseCompression = useCompression; nphost.CompressionThreshold = compressionThreshold; nphost.AddService <IMyTester>(mytester); nphost.Open(); var tcphost = new TcpHost(ipEndpoint, logger, stats); tcphost.UseCompression = useCompression; tcphost.CompressionThreshold = compressionThreshold; tcphost.AddService <INetTester>(tester); tcphost.AddService <IMyTester>(mytester); var valTypes = new ValTypes(); tcphost.AddService <IValTypes>(valTypes); tcphost.Open(); Console.WriteLine("Press Enter to stop the dual host test."); Console.ReadLine(); nphost.Close(); tcphost.Close(); Console.WriteLine("Press Enter to quit."); Console.ReadLine(); }
public void RunHost() { _tester = new Mock <INetTester>(); _tester .Setup(o => o.Min(It.IsAny <int>(), It.IsAny <int>())) .Returns((int a, int b) => Math.Min(a, b)); _tester .Setup(o => o.Range(It.IsAny <int>(), It.IsAny <int>())) .Returns((int a, int b) => Enumerable.Range(a, b).ToDictionary(key => key, el => el)); _ipAddress = IPAddress.Parse("127.0.0.1"); _tcphost = new TcpHost(CreateEndPoint(), zkRepository: _repo); _tcphost.AddService <INetTester>(_tester.Object); _tcphost.Open(); }
private static Task <bool> StartSever(IBuildEngine buildEngine) { var router = new DefaultTargetSelector(); var host = new MSBuildHostService(buildEngine); var result = host.ServerTask; router.Register <IMsBuildHostService, MSBuildHostService>(host); var tcpHost = new TcpHost(new Engine().CreateRequestHandler(router)); result.ContinueWith(_ => { tcpHost.StopListening(); }); tcpHost.StartListening(new System.Net.IPEndPoint(IPAddress.Loopback, 9000)); Console.WriteLine("AvalonStudio MSBuild Host Started:"); return(result); }
public void PrintNetwork() { var parts = TcpHost.Split(':'); var ip = parts[0]; var port = int.Parse(parts[1]); using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) { socket.Connect(ip, port); using (var stream = new NetworkStream(socket)) using (var writer = new StreamWriter(stream)) { writer.WriteLine("! U1 setvar \"device.languages\" \"zpl\""); writer.WriteLine("^XA^FO20,20^A0N,25,25^FDHello World!^FS^XZ"); } } }
public Host(IPEndPoint endPoint, string packageStorageDirectory = null, string sessionExecutionDirectory = null, bool runLocalInProcess = false) { var rootDir = AppDomain.CurrentDomain.BaseDirectory; if (null == packageStorageDirectory) { packageStorageDirectory = Path.Combine(rootDir, @"_dpack"); Directory.CreateDirectory(packageStorageDirectory); } if (null == sessionExecutionDirectory) { sessionExecutionDirectory = Path.Combine(rootDir, @"_dexec"); Directory.CreateDirectory(sessionExecutionDirectory); } //must include some info about this host _serviceHost = new ServiceHost(endPoint, packageStorageDirectory, sessionExecutionDirectory, runLocalInProcess); _tcpHost = new TcpHost(endPoint); _tcpHost.AddService <IServiceHost>(_serviceHost); _tcpHost.Open(); }
private void OnMvcHostServerErrorEvent(TcpHost server, Exception ex) { LogUtils.Error("【MvcHostServerError】", ex); }
public TcpStateContainer(TcpHost client, byte[] dataBuffer) { Client = client; DataBuffer = dataBuffer; }
static void Main(string[] args) { TcpHost host = new TcpHost(); host.Start(45459); }