public TcpConnection(ConnectionToServer connectionToServer, PacketsReceiver packetsReceiver, MetaMonoBehaviours metaMonoBehaviours) : base(metaMonoBehaviours) { this.connectionToServer = connectionToServer; this.packetsReceiver = packetsReceiver; tcpClient = new TcpClient { ReceiveBufferSize = DataBufferSize, SendBufferSize = DataBufferSize }; receiveBuffer = new byte[DataBufferSize]; tcpClient.BeginConnect(ConnectionToServer.ServerIP, ConnectionToServer.ServerPort, ConnectCallback, tcpClient); Logger.LogEvent(LoggerSection.Network, "Started listening for tcp connections"); }
public UdpConnection(ConnectionToServer connectionToServer, MetaMonoBehaviours metaMonoBehaviours, PacketsReceiver packetsReceiver, int localPort) { this.connectionToServer = connectionToServer; this.metaMonoBehaviours = metaMonoBehaviours; this.packetsReceiver = packetsReceiver; ipEndPoint = new IPEndPoint(IPAddress.Parse(ConnectionToServer.ServerIP), ConnectionToServer.ServerPort); udpClient = new UdpClient(localPort); udpClient.Connect(ipEndPoint); udpClient.BeginReceive(OnConnection, null); Logger.LogEvent(LoggerSection.Connection, "Started listening for udp connections"); Packet packet = new Packet(); SendPacket(packet); Logger.LogEvent(LoggerSection.Connection, "Sent first empty udp packet to connect with server's udp"); }