static async Task Main(string[] args) { // Build Netifi Broker Connection var accessKey = 9007199254740991; var accessToken = "kTBDVtfRBO4tHOnZzSyY5ym2kfY="; var transport = new SocketTransport("tcp://localhost:8001/"); var client = new Broker.Client.BrokerClient(accessKey, accessToken, null, null, "quickstart.clients", "client", 0, new SortedDictionary <string, string>(), transport, RSocketOptions.Default); // Connect to Netifi Platform await client.ConnectAsync(); // Create Client to Communicate with the HelloService (included example service) var group = client.Group("quickstart.services.helloservices", new SortedDictionary <string, string>()); var helloService = new HelloService.HelloServiceClient(group); // Create Request to HelloService var request = new HelloRequest(); request.Name = "World"; Console.WriteLine("Sending 'World' to HelloService..."); // Call the HelloService var response = await helloService.SayHello(request, new ReadOnlySequence <byte>()); Console.WriteLine(response.Message); }
public async Task BrokerClientTest() { var accessKey = 9007199254740991; var accessToken = "kTBDVtfRBO4tHOnZzSyY5ym2kfY="; var tags = new SortedDictionary <string, string> { { "key", "value" } }; var transport = new SocketTransport("tcp://localhost:8001/"); var client = new Client.BrokerClient(accessKey, accessToken, null, null, "group", "destination", 0, tags, transport, RSocketOptions.Default); await client.ConnectAsync(); var group = client.Group("com.netifi.broker.brokerServices", new SortedDictionary <string, string>()); var brokerInfoService = new BrokerInfoService.BrokerInfoServiceClient(group); var stream = brokerInfoService.Brokers(new Empty(), new ReadOnlySequence <byte>()); var enumerator = stream.GetAsyncEnumerator(); try { while (await enumerator.MoveNextAsync()) { Console.WriteLine($"Stream Result: {enumerator.Current.ToString()}"); } Console.WriteLine("Stream Done"); } finally { await enumerator.DisposeAsync(); } }
public ThinClient() { m_StateMachine = new StateMachine <ClientState>(); m_StateMachine.Add(ClientState.Browsing, EnterBrowsingState, UpdateBrowsingState, LeaveBrowsingState); m_StateMachine.Add(ClientState.Connecting, EnterConnectingState, UpdateConnectingState, null); m_StateMachine.Add(ClientState.Loading, EnterLoadingState, UpdateLoadingState, null); m_StateMachine.Add(ClientState.Playing, EnterPlayingState, UpdatePlayingState, LeavePlayingState); m_StateMachine.SwitchTo(ClientState.Browsing); m_GameWorld = new GameWorld("ClientWorld"); m_Transport = new SocketTransport(); m_NetworkClient = new NetworkClient(m_Transport); if (Application.isEditor || Game.game.buildId == "AutoBuild") { NetworkClient.clientVerifyProtocol.Value = "0"; } m_NetworkClient.UpdateClientConfig(); m_NetworkStatistics = new NetworkStatisticsClient(m_NetworkClient); m_ChatSystem = new ChatSystemClient(m_NetworkClient); GameDebug.Log("Network client initialized"); m_requestedPlayerSettings.playerName = ClientGameLoop.clientPlayerName.Value; m_requestedPlayerSettings.teamId = -1; }
public bool Init(string[] args) { m_StateMachine = new StateMachine <ClientState>(); m_StateMachine.Add(ClientState.Browsing, EnterBrowsingState, UpdateBrowsingState, LeaveBrowsingState); m_StateMachine.Add(ClientState.Connecting, EnterConnectingState, UpdateConnectingState, null); m_StateMachine.Add(ClientState.Loading, EnterLoadingState, UpdateLoadingState, null); m_StateMachine.Add(ClientState.Playing, EnterPlayingState, UpdatePlayingState, LeavePlayingState); #if UNITY_EDITOR Game.game.levelManager.UnloadLevel(); World.DisposeAllWorlds(); #endif m_GameWorld = new GameWorld("ClientWorld"); m_NetworkTransport = new SocketTransport(); m_NetworkClient = new NetworkClient(m_NetworkTransport); if (Application.isEditor || Game.game.buildId == "AutoBuild") { NetworkClient.clientVerifyProtocol.Value = "0"; } m_NetworkClient.UpdateClientConfig(); m_NetworkStatistics = new NetworkStatisticsClient(m_NetworkClient); m_ChatSystem = new ChatSystemClient(m_NetworkClient); GameDebug.Log("Network client initialized"); m_requestedPlayerSettings.playerName = clientPlayerName.Value; m_requestedPlayerSettings.teamId = -1; Console.AddCommand("disconnect", CmdDisconnect, "Disconnect from server if connected", this.GetHashCode()); Console.AddCommand("prediction", CmdTogglePrediction, "Toggle prediction", this.GetHashCode()); Console.AddCommand("runatserver", CmdRunAtServer, "Run command at server", this.GetHashCode()); Console.AddCommand("respawn", CmdRespawn, "Force a respawn", this.GetHashCode()); Console.AddCommand("nextchar", CmdNextChar, "Select next character", this.GetHashCode()); Console.AddCommand("nc", CmdNextChar, "short version of nextchar", this.GetHashCode()); Console.AddCommand("nextteam", CmdNextTeam, "Select next team", this.GetHashCode()); Console.AddCommand("spectator", CmdSpectator, "Select spectator cam", this.GetHashCode()); Console.AddCommand("matchmake", CmdMatchmake, "matchmake <hostname[:port]/{projectid}>: Find and join a server", this.GetHashCode()); if (args.Length > 0) { targetServer = args[0]; m_StateMachine.SwitchTo(ClientState.Connecting); } else { m_StateMachine.SwitchTo(ClientState.Browsing); } GameDebug.Log("Client initialized"); return(true); }
public static void OnReadTwo(IAsyncResult ar) { GC.Collect(); GC.WaitForPendingFinalizers(); SocketTransport tr = ar.AsyncState as SocketTransport; tr.Socket.EndReceive(ar); string message = Encoding.ASCII.GetString(tr.Buffer); Console.WriteLine("OnReadTwo: " + message); }
protected override void CloseAndSend(BinaryWriter request, uint lengthPos) { if (UseV100Plus) { request.Seek((int)lengthPos, SeekOrigin.Begin); request.Write(IPAddress.HostToNetworkOrder((int)(request.BaseStream.Length - lengthPos - sizeof(int)))); } request.Seek(0, SeekOrigin.Begin); var buf = new MemoryStream(); request.BaseStream.CopyTo(buf); SocketTransport.Send(new EMessage(buf.ToArray())); }
bool AcceptClient(TcpClient client, out ServerConnection conn) { //TODO: use the right abstraction here, probably using the Server class SocketTransport transport = new SocketTransport(); client.Client.Blocking = true; transport.SocketHandle = (long)client.Client.Handle; transport.Stream = client.GetStream(); //Connection conn = new Connection (transport); //Connection conn = new ServerConnection (transport); //ServerConnection conn = new ServerConnection (transport); conn = new ServerConnection(transport); conn.Server = this; //conn.Id = Id; if (conn.Transport.Stream.ReadByte() != 0) { return(false); } //conn.isConnected = true; SaslPeer remote = new SaslPeer(); remote.stream = transport.Stream; SaslServer local = new SaslServer(); local.stream = transport.Stream; local.Guid = Id; local.Peer = remote; remote.Peer = local; bool success = local.Authenticate(); Console.WriteLine("Success? " + success); if (!success) { return(false); } conn.UserId = ((SaslServer)local).uid; //conn.isAuthenticated = true; return(true); }
private IApiTransport GetTransport() { var apiUri = Config.GetConfig("ApiUri", ""); IApiTransport transport; if (apiUri.StartsWith("http")) { transport = new HttpTransport(); } else // if (apiUri.StartsWith("Tcp")) { transport = new SocketTransport(); } var arr = apiUri.Split(new char[] { ':', '/' }, StringSplitOptions.RemoveEmptyEntries); transport.Init(arr[1], Convert.ToInt32(arr[2])); return(transport); }
static async Task Main(string[] args) { var serviceName = "helloservice-" + Guid.NewGuid().ToString(); // Build Netifi Broker Connection var accessKey = 9007199254740991; var accessToken = "kTBDVtfRBO4tHOnZzSyY5ym2kfY="; var transport = new SocketTransport("tcp://localhost:8001/"); var client = new Broker.Client.BrokerClient(accessKey, accessToken, null, null, "quickstart.services.helloservices", "helloservice", 0, new SortedDictionary <string, string>(), transport, RSocketOptions.Default); // Add Service to Respond to Requests var service = new DefaultHelloService(); client.AddService(service); // Connect to Netifi Platform await client.ConnectAsync(); // Keep the Service Running await Task.Delay(Timeout.Infinite); }
public void Setup() { var config = new StatsDConfiguration { Host = "127.0.0.1", }; var endpointSource1 = EndPointFactory.MakeEndPointSource( config.Host, config.Port, config.DnsLookupInterval); var endpointSource2 = EndPointFactory.MakeEndPointSource( config.Host, config.Port + 1, config.DnsLookupInterval); var switcher = new MillisecondSwitcher(endpointSource1, endpointSource2); _transport = new SocketTransport(endpointSource1, SocketProtocol.Udp); _transportSwitched = new SocketTransport(switcher, SocketProtocol.Udp); }
void IEClientMsgSink.ServerVersion(int version, string time) { base.ServerVersion = version; if (!UseV100Plus) { if (!CheckServerVersion(MinServerVer.MinVersion, "")) { ReportUpdateTws(""); return; } } else if (ServerVersion < Constants.MinVersion || ServerVersion > Constants.MaxVersion) { Wrapper.Error(ClientId, EClientErrors.UNSUPPORTED_VERSION.Code, EClientErrors.UNSUPPORTED_VERSION.Message); return; } if (ServerVersion >= 3) { if (ServerVersion < MinServerVer.Linking) { var buf = new List <byte>(); buf.AddRange(Encoding.UTF8.GetBytes(ClientId.ToString())); buf.Add(Constants.Eol); SocketTransport.Send(new EMessage(buf.ToArray())); } } ServerTime = time; IsConnected = true; if (!AsyncEConnect) { StartApi(); } }
public void Setup() { var config = new StatsDConfiguration { // if you want to verify that stats are received, // you will need the IP of suitable local test stats server Host = "127.0.0.1", Prefix = "testmetric" }; var endpointSource = EndpointParser.MakeEndPointSource( config.Host, config.Port, config.DnsLookupInterval); _transport = new SocketTransport(endpointSource, SocketProtocol.Udp); _adaptedStatsDPublisher = new StatsDPublisher(config); _adaptedStatsDPublisher.Increment("startup.ud"); _udpSender = new BufferBasedStatsDPublisher(config, _transport); _udpSender.Increment("startup.ud"); }
public static void OnReadOne(IAsyncResult ar) { SocketTransport tr = ar.AsyncState as SocketTransport; string message = Encoding.ASCII.GetString(tr.Buffer); Console.WriteLine("OnReadOne: " + message); Socket socket = tr.Socket; ar = null; tr = null; // SocketTransport 1 would become eligible for garbage collection here // if the caller of OnReadOne didn't hold a reference as a local variable. // // As soon as we exit from this method, our caller exits too // and the local reference will be no more and SocketTransport 1 // can be garbage collected. It doesn't matter whether we // call EndReceive or not, as illustrated with the triggered GC // in OnReadTwo() and the one after pressing enter in Main. SocketTransport tr2 = new SocketTransport("2", socket, new byte[64]); tr2.Socket.BeginReceive(tr2.Buffer, 0, tr2.Buffer.Length, SocketFlags.None, OnReadTwo, tr2); }
static void Main(string[] args) { listener = new TcpListener(IPAddress.Any, 2055); listener.Start(); Thread t = new Thread(TcpService); t.Start(); Console.WriteLine("TCP server started, listening to port 2055"); SocketTransport tr = new SocketTransport("1", new MySocket("1", AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp), new byte[64]); tr.Socket.Connect(IPAddress.Loopback, 2055); tr.Socket.BeginReceive(tr.Buffer, 0, tr.Buffer.Length, SocketFlags.None, OnReadOne, tr); tr = null; Console.WriteLine("Press enter to trigger GC"); Console.ReadLine(); GC.Collect(); GC.WaitForPendingFinalizers(); Console.WriteLine("Press enter to exit"); Console.ReadLine(); }
public ThinClient() { m_StateMachine = new StateMachine <ClientState>(); m_StateMachine.Add(ClientState.Browsing, EnterBrowsingState, UpdateBrowsingState, LeaveBrowsingState); m_StateMachine.Add(ClientState.Connecting, EnterConnectingState, UpdateConnectingState, null); m_StateMachine.Add(ClientState.Loading, EnterLoadingState, UpdateLoadingState, null); m_StateMachine.Add(ClientState.Playing, EnterPlayingState, UpdatePlayingState, LeavePlayingState); m_StateMachine.SwitchTo(m_GameWorld, ClientState.Browsing); #pragma warning disable 618 // we're keeping World.Active until we can properly remove them all // TODO (timj) not compatible with dots netcode m_GameWorld = World.Active; World.Active.CreateSystem <GameTimeSystem>(); #pragma warning restore 618 m_Transport = new SocketTransport(); m_NetworkClient = new NetworkClient(m_Transport); if (Application.isEditor || Game.game.buildId == "AutoBuild") { NetworkClient.clientVerifyProtocol.Value = "0"; } m_NetworkClient.UpdateClientConfig(); m_NetworkStatistics = new NetworkStatisticsClient(m_NetworkClient); m_ChatSystem = new ChatSystemClient(); GameDebug.Log("Network client initialized"); m_requestedPlayerSettings.playerName = ClientGameLoop.clientPlayerName.Value; m_requestedPlayerSettings.teamId = -1; }
public bool Init(string[] args) { // Set up statemachine for ServerGame m_StateMachine = new StateMachine <ServerState>(); m_StateMachine.Add(ServerState.Idle, null, UpdateIdleState, null); m_StateMachine.Add(ServerState.Loading, null, UpdateLoadingState, null); m_StateMachine.Add(ServerState.Active, EnterActiveState, UpdateActiveState, LeaveActiveState); m_StateMachine.SwitchTo(ServerState.Idle); m_NetworkTransport = new SocketTransport(NetworkConfig.serverPort.IntValue, serverMaxClients.IntValue); var listenAddresses = NetworkUtils.GetLocalInterfaceAddresses(); if (listenAddresses.Count > 0) { Console.SetPrompt(listenAddresses[0] + ":" + NetworkConfig.serverPort.Value + "> "); } GameDebug.Log("Listening on " + string.Join(", ", NetworkUtils.GetLocalInterfaceAddresses()) + " on port " + NetworkConfig.serverPort.IntValue); m_NetworkServer = new NetworkServer(m_NetworkTransport); if (Game.game.clientFrontend != null) { var serverPanel = Game.game.clientFrontend.serverPanel; serverPanel.SetPanelActive(true); serverPanel.serverInfo.text += "Listening on:\n"; foreach (var a in NetworkUtils.GetLocalInterfaceAddresses()) { serverPanel.serverInfo.text += a + ":" + NetworkConfig.serverPort.IntValue + "\n"; } } m_NetworkServer.UpdateClientInfo(); m_NetworkServer.serverInfo.compressionModel = m_Model; if (serverServerName.Value == "") { serverServerName.Value = MakeServername(); } m_ServerQueryProtocolServer = new SQP.SQPServer(NetworkConfig.serverSQPPort.IntValue > 0? NetworkConfig.serverSQPPort.IntValue : NetworkConfig.serverPort.IntValue + NetworkConfig.sqpPortOffset); #if UNITY_EDITOR Game.game.levelManager.UnloadLevel(); World.DisposeAllWorlds(); #endif m_GameWorld = new GameWorld("ServerWorld"); m_NetworkStatistics = new NetworkStatisticsServer(m_NetworkServer); m_ChatSystem = new ChatSystemServer(m_Clients, m_NetworkServer); GameDebug.Log("Network server initialized"); Console.AddCommand("load", CmdLoad, "Load a named scene", this.GetHashCode()); Console.AddCommand("unload", CmdUnload, "Unload current scene", this.GetHashCode()); Console.AddCommand("respawn", CmdRespawn, "Respawn character (usage : respawn playername|playerId)", this.GetHashCode()); Console.AddCommand("servername", CmdSetServerName, "Set name of the server", this.GetHashCode()); Console.AddCommand("beginnetworkprofile", CmdBeginNetworkProfile, "begins a network profile", this.GetHashCode()); Console.AddCommand("endnetworkprofile", CmdEndNetworkProfile, "Ends a network profile and analyzes. [optional] filepath for model data", this.GetHashCode()); Console.AddCommand("loadcompressionmodel", CmdLoadNetworkCompressionModel, "Loads a network compression model from a filepath", this.GetHashCode()); Console.AddCommand("list", CmdList, "List clients", this.GetHashCode()); CmdLoad(args); Game.SetMousePointerLock(false); m_ServerStartTime = Time.time; GameDebug.Log("Server initialized"); Console.SetOpen(false); return(true); }
bool AcceptClient(TcpClient client, out ServerConnection conn) { //TODO: use the right abstraction here, probably using the Server class SocketTransport transport = new SocketTransport(); client.Client.Blocking = true; transport.SocketHandle = (long)client.Client.Handle; transport.Stream = client.GetStream(); //Connection conn = new Connection (transport); //Connection conn = new ServerConnection (transport); //ServerConnection conn = new ServerConnection (transport); conn = new ServerConnection(transport); conn.Server = this; conn.Id = Id; if (conn.Transport.Stream.ReadByte() != 0) return false; conn.isConnected = true; SaslPeer remote = new SaslPeer(); remote.stream = transport.Stream; SaslServer local = new SaslServer(); local.stream = transport.Stream; local.Guid = Id; local.Peer = remote; remote.Peer = local; bool success = local.Authenticate(); Console.WriteLine("Success? " + success); if (!success) return false; conn.UserId = ((SaslServer)local).uid; conn.isAuthenticated = true; return true; }
public bool Init(string[] args) { // Set up statemachine for ServerGame m_StateMachine = new StateMachine <ServerState>(); m_StateMachine.Add(ServerState.Idle, null, UpdateIdleState, null); m_StateMachine.Add(ServerState.Loading, null, UpdateLoadingState, null); m_StateMachine.Add(ServerState.Active, EnterActiveState, UpdateActiveState, LeaveActiveState); m_StateMachine.SwitchTo(ServerState.Idle); #if USE_UNET m_NetworkTransport = new UNETTransport(); if (!m_NetworkTransport.Init(serverPort.IntValue, 32)) { return(false); } m_NetworkServer = new NetworkServer(m_NetworkTransport); m_ServerBroadcast = new UNETServerBroadcast(m_NetworkTransport.hostId, new UNETBroadcastConfig(), 7913); // TODO (petera) what if these (max clients and name) changes during play m_ServerBroadcast.gameInfo.maxPlayers = serverMaxClients.IntValue; if (serverServerName.Value.Length == 0) { serverServerName.Value = MakeServername(); } m_ServerBroadcast.gameInfo.servername = serverServerName.Value; GameDebug.Log("Server name: '" + m_ServerBroadcast.gameInfo.servername + "'"); m_ServerBroadcast.gameInfo.levelname = "-"; m_ServerBroadcast.gameInfo.gamemode = "-"; m_ServerBroadcast.Start(); #else m_NetworkTransport = new SocketTransport(serverPort.IntValue); GameDebug.Log("Listening on " + string.Join(", ", NetworkUtils.GetLocalInterfaceAddresses()) + " on port " + serverPort.IntValue); m_NetworkServer = new NetworkServer(m_NetworkTransport); if (Game.game.clientFrontend != null) { var serverPanel = Game.game.clientFrontend.serverPanel; serverPanel.SetPanelActive(true); serverPanel.serverInfo.text += "Listening on:\n"; foreach (var a in NetworkUtils.GetLocalInterfaceAddresses()) { serverPanel.serverInfo.text += a + ":" + serverPort.IntValue + "\n"; } } #endif m_NetworkServer.UpdateClientInfo(); m_NetworkServer.clientInfo.compressionModel = m_Model; m_ServerQueryProtocolServer = new SQP.SQPServer(serverSQPPort.IntValue); var info = m_ServerQueryProtocolServer.ServerInfoData; info.BuildId = Game.game.buildId; info.Port = (ushort)serverPort.IntValue; info.CurrentPlayers = 0; info.GameType = "Deathmatch"; info.Map = ""; info.MaxPlayers = 32; info.ServerName = MakeServername(); #if UNITY_EDITOR Game.game.levelManager.UnloadLevel(); World.DisposeAllWorlds(); #endif m_GameWorld = new GameWorld("ServerWorld"); m_NetworkStatistics = new NetworkStatisticsServer(m_NetworkServer); m_ChatSystem = new ChatSystemServer(m_Clients, m_NetworkServer); GameDebug.Log("Network server initialized"); Console.AddCommand("load", CmdLoad, "Load a named scene", this.GetHashCode()); Console.AddCommand("unload", CmdUnload, "Unload current scene", this.GetHashCode()); Console.AddCommand("respawn", CmdRespawn, "Respawn character (usage : respawn playername|playerId)", this.GetHashCode()); Console.AddCommand("servername", CmdSetServerName, "Set name of the server", this.GetHashCode()); Console.AddCommand("beginnetworkprofile", CmdBeginNetworkProfile, "begins a network profile", this.GetHashCode()); Console.AddCommand("endnetworkprofile", CmdEndNetworkProfile, "Ends a network profile and analyzes. [optional] filepath for model data", this.GetHashCode()); Console.AddCommand("loadcompressionmodel", CmdLoadNetworkCompressionModel, "Loads a network compression model from a filepath", this.GetHashCode()); Console.AddCommand("list", CmdList, "List clients", this.GetHashCode()); CmdLoad(args); Game.SetMousePointerLock(false); m_ServerStartTime = Time.time; GameDebug.Log("Server initialized"); Console.SetOpen(false); return(true); }
public bool Init(string[] args) { m_StateMachine = new StateMachine <ClientState>(); m_StateMachine.Add(ClientState.Browsing, EnterBrowsingState, UpdateBrowsingState, LeaveBrowsingState); m_StateMachine.Add(ClientState.Connecting, EnterConnectingState, UpdateConnectingState, null); m_StateMachine.Add(ClientState.Loading, EnterLoadingState, UpdateLoadingState, null); m_StateMachine.Add(ClientState.Playing, EnterPlayingState, UpdatePlayingState, LeavePlayingState); #if UNITY_EDITOR Game.game.levelManager.UnloadLevel(); #endif m_GameWorld = new GameWorld("ClientWorld"); m_NetworkTransport = new SocketTransport(); m_NetworkClient = new NetworkClient(m_NetworkTransport); if (Application.isEditor || Game.game.buildId == "AutoBuild") { NetworkClient.clientVerifyProtocol.Value = "0"; } m_NetworkClient.UpdateClientConfig(); m_NetworkStatistics = new NetworkStatisticsClient(m_NetworkClient); m_ChatSystem = new ChatSystemClient(m_NetworkClient); GameDebug.Log("Network client initialized"); m_requestedPlayerSettings.playerName = clientPlayerName.Value; m_requestedPlayerSettings.teamId = -1; Console.AddCommand("disconnect", CmdDisconnect, "Disconnect from server if connected", this.GetHashCode()); Console.AddCommand("prediction", CmdTogglePrediction, "Toggle prediction", this.GetHashCode()); Console.AddCommand("runatserver", CmdRunAtServer, "Run command at server", this.GetHashCode()); Console.AddCommand("respawn", CmdRespawn, "Force a respawn", this.GetHashCode()); Console.AddCommand("nextchar", CmdNextChar, "Select next character", this.GetHashCode()); Console.AddCommand("nextteam", CmdNextTeam, "Select next character", this.GetHashCode()); Console.AddCommand("spectator", CmdSpectator, "Select spectator cam", this.GetHashCode()); Console.AddCommand("matchmake", CmdMatchmake, "matchmake <hostname[:port]/{projectid}>: Find and join a server", this.GetHashCode()); if (args.Length > 0) { targetServer = args[0]; m_StateMachine.SwitchTo(ClientState.Connecting); } else { m_StateMachine.SwitchTo(ClientState.Browsing); } ReplicatedPrefabMgr.Initialize(); ClientServerSystemManager.InitClientSystems(); World.Active.GetExistingSystem <TickClientSimulationSystem>().Enabled = true; World.Active.GetExistingSystem <TickClientPresentationSystem>().Enabled = true; Unity.Networking.Transport.NetworkEndPoint ep = Unity.Networking.Transport.NetworkEndPoint.Parse(targetServer, (ushort)NetworkConfig.netcodeServerPort); World clientWorld = ClientServerSystemManager.clientWorld; EntityManager em = clientWorld.EntityManager; Entity ent = clientWorld.GetExistingSystem <NetworkStreamReceiveSystem>().Connect(ep); em.AddComponentData(ent, new NetworkStreamInGame()); GameDebug.Log("Client initialized"); return(true); }
public static void Main(string[] args) { bool isServer; int port; string hostname = "127.0.0.1"; //IPAddress ipaddr = IPAddress.Parse ("127.0.0.1"); if (args.Length == 2 && args[0] == "server") { isServer = true; port = Int32.Parse(args[1]); } else if (args.Length == 3 && args[0] == "client") { isServer = false; hostname = args[1]; port = Int32.Parse(args[2]); } else { Console.Error.WriteLine("Usage: test-server-tcp [server PORT|client HOSTNAME PORT]"); return; } Connection conn; ObjectPath myOpath = new ObjectPath("/org/ndesk/test"); string myNameReq = "org.ndesk.test"; if (!isServer) { SocketTransport transport = new SocketTransport(); transport.Open(hostname, port); conn = new Connection(transport); DemoObject demo = conn.GetObject <DemoObject> (myNameReq, myOpath); demo.GiveNoReply(); //float ret = demo.Hello ("hi from test client", 21); float ret = 200; while (ret > 5) { ret = demo.Hello("hi from test client", (int)ret); Console.WriteLine("Returned float: " + ret); System.Threading.Thread.Sleep(1000); } } else { TcpListener server = new TcpListener(IPAddress.Any, port); server.Start(); while (true) { Console.WriteLine("Waiting for client on " + port); TcpClient client = server.AcceptTcpClient(); Console.WriteLine("Client accepted"); //TODO: use the right abstraction here, probably using the Server class SocketTransport transport = new SocketTransport(); transport.Stream = client.GetStream(); conn = new Connection(transport); //conn.SocketHandle = (long)clientSocket.Handle; //ConnectionHandler.Handle (conn); //in reality a thread per connection is of course too expensive ConnectionHandler hnd = new ConnectionHandler(conn); new Thread(new ThreadStart(hnd.Handle)).Start(); Console.WriteLine(); } } }