public void SetUp() { // At some point, I stopped considering this setup easy server = new FlowServer(LazyOptions) .UsingModule(new TcpModule(LocalAddress, Port1)) .UsingWrapper(new Utf8DataWrapper()) .Start(); var manualReset = new ManualResetEvent(false); for (var i = 0; i < destinationClients.Length; i++) { var index = i; void add(DestinationClient client) { destinationClients[index] = client; manualReset.Set(); } server.ClientConnected += add; clients[index] = new FlowClient(LocalAddress, Port1) .UsingWrapper(new Utf8DataWrapper()); clients[index].Connect(); manualReset.WaitOne(); manualReset.Reset(); server.ClientConnected -= add; } }
public void SendFrom(string clientId, Vector3 _position, Quaternion _rotation) { GameObject prefab = Instantiate(References.defaults.SERVER_PLAYER_PREFAB, _position, _rotation); ServerPlayerManager.AddPlayerPrefab(prefab, clientId); // spawn new client onn all existing clients SendPackageFrom(clientId, new SpawnFlowServerPackage() { position = _position, rotation = _rotation }).SendAll(SendMethod.ReliableOrdered); // spawn already existing clients on the newly connected client FlowServer.IterateConnectedClients((FlowClientServer client) => { if (client.id != clientId) { SendPackageFrom(client.id, new SpawnFlowServerPackage() { position = _position, rotation = _rotation }).Send(SendMethod.ReliableOrdered, clientId); } return(true); }); }
public void Initialize(FlowServer server) { if (owner != null) { throw new Exception("Module already initialized. Maybe you called the 'Initialize(FlowServer)' method yourself?"); } owner = server; }
public void SetUp() { server = new FlowServer() .UsingModule(new TcpModule(LocalAddress, Port1)) .UsingWrapper(new Utf8DataWrapper()) .Start(); server.ClientConnected += c => destinationClient = c; client = new FlowClient(LocalAddress, Port1) .UsingWrapper(new Utf8DataWrapper()); client.Connect(); }
/// <summary> /// Sends the package to all connected peers /// </summary> /// <param name="method"></param> public void SendAll(SendMethod method) { if (isClient) { throw new NotSupportedException("SendAll is not supported on the client."); } FlowServer.IterateConnectedClients((FlowClientServer client) => { client.peer.Send(writer, (DeliveryMethod)method); return(true); }); }
public static void Start(int port) { var server = new FlowServer(options) .UsingModule(new TcpModule(IPAddress.Any, port)) .UsingModule(new WebSocketModule("127.0.0.1:3333")); server.ClientConnected += Server_ClientConnected; server.ClientDisconnected += Server_ClientDisconnected; server.Bind <UserInput>((int)CsEventId.SendName, NameReceive); server.Bind <UserInput>((int)CsEventId.SendMessage, MessageReceive); server.Start(); Console.WriteLine("The server is started"); }
/// <summary> /// Sends the package to only the clients defined in clientIds /// </summary> /// <param name="method"></param> /// <param name="clientIds"></param> public void SendExclusively(SendMethod method, string[] clientIds) { if (isClient) { throw new NotSupportedException("SendMultiple is not supported on the client."); } FlowServer.IterateConnectedClients((FlowClientServer client) => { if (StringInArray(clientIds, client.id)) { client.peer.Send(writer, (DeliveryMethod)method); } return(true); }); }
public void Group_Add_ShouldNotAddClientFromOtherServer() { var additionalServer = new FlowServer() .UsingModule(new TcpModule(LocalAddress, Port2)) .Start(); DestinationClient additionalClient = null; additionalServer.ClientConnected += c => additionalClient = c; new FlowClient(LocalAddress, Port2).Connect(); var group = new FlowGroup(server); Assert.Throws(typeof(Exception), () => group.Add(additionalClient)); }
public void SetUp() { server = new FlowServer() .UsingModule(new TcpModule(LocalAddress, Port1)) .Start(); }