public SocketTasksAwaiter(SocketTasks sockets) { this.sockets = sockets; continuation = null; pollUntilDone(); }
private void HandleReceiveFromClient(int fromClientId, byte channelId, ArraySegment <byte> payload) { if (connectTask != null) { connectTask.Tasks[0].Success = true; connectTask.Tasks[0].IsDone = true; connectTask = null; } RelayEvent re = new RelayEvent() { ChannelName = channelIdToName[channelId], ClientId = (ulong)fromClientId, payload = payload, receiveTime = timeSinceStartup, eventType = NetEventType.Data }; //Debug.Log("Received payload from client " + fromClientId + " bytes: " + payload.Count+" channel: "+re.ChannelName); //Debug.Log("payload-data: " + BitConverter.ToString(payload.Array, payload.Offset, payload.Count)); lock (receivedEvents) { receivedEvents.Enqueue(re); } }
public bool StartJobs(SocketTasks tasks) { if (Stopped || WasStarted) { return(false); } WasStarted = true; if (tasks.HasFlag(SocketTasks.Accept)) { SetupAccept(); } if (tasks.HasFlag(SocketTasks.Receive)) { SetupReceive(); } if (tasks.HasFlag(SocketTasks.ReceiveFrom)) { SetupReceiveFrom(); } if (tasks.HasFlag(SocketTasks.ReceiveMessageFrom)) { SetupReceiveMessageFrom(); } return(true); }
public override SocketTasks StartServer() { lock (receivedEvents) { receivedEvents.Clear(); } IsHost = true; connectTask = SocketTask.Working.AsTasks(); StartSocket(); SendStartHost(RoomPassword, RoomNameToCreate); return(connectTask); }
public override SocketTasks StartClient() { lock (receivedEvents) { receivedEvents.Clear(); } IsHost = false; connectTask = SocketTask.Working.AsTasks(); StartSocket(); SendStartClient(RoomIdToConnect, RoomPassword); return(connectTask); }
public void OnClick() { if (NetworkManager.Singleton.IsClient) { NetworkManager.Singleton.StopClient(); } if (!NetworkManager.Singleton.IsClient && !NetworkManager.Singleton.IsServer) { ChangeIpAdress(); SocketTasks client = NetworkManager.Singleton.StartClient(); if (!client.Success) { print("algo deu errado!"); } } }
private void HandleDisconnect() { Debug.Log("HandleDisconnect ClientId = " + ClientId); if (connectTask != null) { connectTask.Tasks[0].Success = false; connectTask.Tasks[0].IsDone = true; connectTask = null; } lock (startStopClientLock) { if (started) { started = false; tcpClient.Dispose(); tcpClient = null; } } if (ClientId != -1) { RelayEvent re = new RelayEvent() { ChannelName = mlapidefaultChannel, ClientId = (ulong)ClientId, payload = new ArraySegment <byte>(), receiveTime = timeSinceStartup, eventType = NetEventType.Disconnect }; lock (receivedEvents) { receivedEvents.Enqueue(re); } ClientId = -1; } }
private void HandleStartHostResponse(int clientId, int roomId) { if (connectTask != null) { connectedRoomId = roomId; this.hostClientId = (uint)clientId; RelayEvent re = new RelayEvent() { ChannelName = mlapidefaultChannel, ClientId = (ulong)clientId, payload = new ArraySegment <byte>(), receiveTime = timeSinceStartup, eventType = NetEventType.Connect }; connectTask.Tasks[0].Success = true; connectTask.Tasks[0].IsDone = true; connectTask = null; /*lock (receivedEvents) * { * receivedEvents.Enqueue(re); * }*/ } }
public static SocketTasksAwaiter GetAwaiter(this SocketTasks sockets) => new SocketTasksAwaiter(sockets);
public Awaiter(SocketTasks socketTasks) => this.socketTasks = socketTasks;