From 2e4e4c4693e123ce6e0e11f3a367f46d3505f3d0 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Mon, 9 Dec 2024 14:02:32 +0100 Subject: [PATCH] Multiclient is working --- Client.cs | 8 ++++++++ SiteServer.cs | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/Client.cs b/Client.cs index 823bcf1..190c2b2 100644 --- a/Client.cs +++ b/Client.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Collections.Concurrent; using System.Net.Sockets; +using System.IO; namespace Passer.Control { @@ -9,6 +10,7 @@ namespace Passer.Control { public UdpClient udpClient; public string ipAddress; public int port; + public Stream dataStream; public byte networkId = 0; @@ -48,9 +50,15 @@ namespace Passer.Control { this.udpClient = udpClient; this.ipAddress = null; this.port = port; + this.dataStream = new EchoStream(); clients.Add(this); } + public virtual void ProcessMessages() { + while (this.messageQueue.TryDequeue(out IMessage msg)) + ProcessMessage(msg); + } + public void ProcessMessage(IMessage msg) { switch (msg) { case ClientMsg clientMsg: diff --git a/SiteServer.cs b/SiteServer.cs index f198299..24e42b2 100644 --- a/SiteServer.cs +++ b/SiteServer.cs @@ -1,9 +1,29 @@ +using System.Diagnostics; using System.IO; using System.Threading.Tasks; namespace Passer.Control { public static class SiteServer { + //public static async Task ReceiveData() { + // while (true) { + // //foreach (var client in Client.clients) { + + // for (int ix = 0; ix < Client.clients.Count; ix++) { + // if (ix > 0) + // UnityEngine.Debug.Log("Client2 "); + // Client client = Client.clients[ix]; + // if (client == null) + // continue; + + // byte packetSize = (byte)client.dataStream.ReadByte(); + // if (packetSize != 0xFF) + // await ReceiveData(client.dataStream, client, packetSize); + // // else timeout + // } + // } + //} + public static async Task ReceiveData(Stream dataStream, Client client) { while (true) { byte packetSize = (byte)dataStream.ReadByte();