void OnGUI() { // client GUI.enabled = !client.Connected; if (GUI.Button(new Rect(0, 0, 120, 20), "Connect Client")) { client.Connect("localhost", 1337); } GUI.enabled = client.Connected; if (GUI.Button(new Rect(130, 0, 120, 20), "Disconnect Client")) { client.Disconnect(); } // server GUI.enabled = !server.Active; if (GUI.Button(new Rect(0, 25, 120, 20), "Start Server")) { server.Start(1337); } GUI.enabled = server.Active; if (GUI.Button(new Rect(130, 25, 120, 20), "Stop Server")) { server.Stop(); } GUI.enabled = true; }
public void StartServer() { server = new Telepathy.Server(); server.Start(port); isServer = true; OnServerStarted?.Invoke(); }
void OnGUI() { // server GUI.enabled = !server.Active; if (GUI.Button(new Rect(0, 25, 120, 20), "Start Server")) { if (!server.Active) { server.Start(1337); } } GUI.enabled = server.Active; if (GUI.Button(new Rect(130, 25, 120, 20), "Stop Server")) { if (server.Active) { server.Stop(); //clear list Players.Clear(); } } GUI.enabled = true; }
public void Start(int port) { _server.Start(port); _server.OnConnected += OnClientConnected; _server.OnDisconnected += OnClientDisconnected; _server.OnData += OnClientData; }
void OnGUI() { // client GUI.enabled = !client.Connected; if (GUI.Button(new Rect(0, 0, 120, 20), "Connect Client")) { client.Connect("localhost", 1337); GameObject.Instantiate(PlayerPrefab, Vector3.zero, Quaternion.identity); } GUI.enabled = client.Connected; if (GUI.Button(new Rect(130, 0, 120, 20), "Disconnect Client")) { client.Disconnect(); } // server GUI.enabled = !server.Active; if (GUI.Button(new Rect(0, 25, 120, 20), "Start Server")) { server.Start(1337); } GUI.enabled = server.Active; if (GUI.Button(new Rect(130, 25, 120, 20), "Stop Server")) { server.Stop(); } GUI.enabled = true; }
private void StartTelepathyServer(ushort port) { server = new Telepathy.Server(); server.Start(port); started = true; Debug.Log($"Telepathy started at port {port}"); }
public void StartTCPServer(int port) { // had to set these to 0 or else the TCP connection would timeout after the default 5 seconds. Investivate further. _server.SendTimeout = 0; _server.ReceiveTimeout = 0; _server.Start(port); }
static void Main(string[] args) { server = new Telepathy.Server(); server.Start(1337); Task.Run(() => { while (server.Active) { Telepathy.Message msg; while (server.GetNextMessage(out msg)) { switch (msg.eventType) { case Telepathy.EventType.Connected: // msg.connectionIdはクライアント接続時に+1される数値。1始まり Console.WriteLine("Telepathy.EventType.Connected : msg.connectionId=" + msg.connectionId); break; case Telepathy.EventType.Data: Console.WriteLine("Telepathy.EventType.Data : msg.connectionId=" + msg.connectionId + ", msg.data" + System.Text.Encoding.UTF8.GetString(msg.data)); // reply Console.WriteLine("send massage from server..."); server.Send(msg.connectionId, System.Text.Encoding.UTF8.GetBytes("send message from server...")); break; case Telepathy.EventType.Disconnected: Console.WriteLine("Telepathy.EventType.Disconnected : msg.connectionId=" + msg.connectionId); break; } } } }); bool break_flag = false; while (break_flag == false) { ConsoleKey k = Console.ReadKey().Key; switch (k) { case ConsoleKey.L: break; case ConsoleKey.Escape: break_flag = true; break; } } server.Stop(); }
public void Run() { try { networkPlayersDictionary = new Dictionary <long, NetworkPlayer>(); server = new Telepathy.Server(); server.Start(1337); while (server.Active) { // reply to each incoming message Message msg; while (server.GetNextMessage(out msg)) { if (msg.eventType == EventType.Connected) { OnClientConnected(msg.connectionId); } else if (msg.eventType == EventType.Data) { server.Send(msg.connectionId, msg.data); OnMessageReceived(new NetworkMessage(msg.data), msg.connectionId); } else if (msg.eventType == EventType.Disconnected) { OnClientDisconnected(msg.connectionId); } } SendPlayerPositions(); System.Threading.Thread.Sleep(15); } } catch (Exception ex) { Console.WriteLine($"Error: {ex.Message}"); } }
public override void ServerStart() => server.Start(port);
public void StartServer(int port) { server.Start(port); OnServerStarted(); Chat.FixedUpdate += FixedUpdate; }