public void Open() { if (IsOpened) { return; } if (userSyncContext) { syncContext = SynchronizationContext.Current; if (syncContext == null) { syncContext = new SnowballSynchronizationContext(10); SynchronizationContext.SetSynchronizationContext(syncContext); } } int port = portNumber; if (listenPortNumber != 0) { port = listenPortNumber; } udpTerminal = new UDPTerminal(port, bufferSize); udpTerminal.SyncContext = syncContext; udpTerminal.OnReceive += OnUnreliableReceived; udpTerminal.ReceiveStart(); IsOpened = true; }
void OnConnectedInternal(string ip, TCPConnection connection) { if (connection != null) { connection.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); lock (serverNodeLocker) { serverNode = new ComSnowballNode(connection); } udpTerminal.ReceiveStart(); connection.OnDisconnected = OnDisconnectedInternal; connection.OnPoll = OnPoll; IssueIdData ldata = new IssueIdData(); if (UserId != 0) { if (previousServerNode != null && previousServerNode.AesEncrypter != null) { ldata.Id = UserId; ldata.encryptionData = previousServerNode.AesEncrypter.Encrypt(Global.ReconnectRawData); } else { UserId = 0; } } if (UserId == 0) { ldata.Id = UserId; } SendInternal((short)PreservedChannelId.IssueId, ldata); healthLostCount = 0; //Util.Log("Client:Connected"); isConnecting = false; } else { isConnecting = false; OnConnectError(ip); } }
public void Open() { if (IsOpened) { return; } if (userSyncContext) { syncContext = SynchronizationContext.Current; if (syncContext == null) { syncContext = new SnowballSynchronizationContext(10); SynchronizationContext.SetSynchronizationContext(syncContext); } } RSAParameters publicKey; RSAParameters privateKey; RsaKeyGenerate(out publicKey, out privateKey); RsaPublicKey = publicKey; RsaPrivateKey = privateKey; rsaDecrypter = new RsaDecrypter(RsaPrivateKey); udpTerminal = new UDPTerminal(portNumber, bufferSize); udpTerminal.SyncContext = syncContext; udpTerminal.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); tcpListener = new TCPListener(portNumber); tcpListener.SyncContext = syncContext; tcpListener.ConnectionBufferSize = bufferSize; tcpListener.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); tcpListener.OnConnected += OnConnectedInternal; udpTerminal.OnReceive += OnUnreliableReceived; tcpListener.Start(); udpTerminal.ReceiveStart(); IsOpened = true; healthTimer.Start(); removeNodeCheckTimer.Start(); }