Example #1
0
 private void SetupConnection(Socket s)
 {
     SetTcpKeepAlive(s);
     EndPoint   = ((IPEndPoint)s.RemoteEndPoint);
     Connection = new InternalSyncIOConnectedClient(s, Packager);
     Connection.BeginReceve(ReceveHandler);
     Connection.OnDisconnect += Connection_OnDisconnect;
 }
Example #2
0
 /// <summary>
 /// Possably add support for connecting to multiple servers.
 /// </summary>
 private Socket NewSocket()
 {
     Connection?.Disconnect(null);
     Connection = null;
     if (Protocal == TransportProtocal.IPv6)
     {
         return(new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp));
     }
     else
     {
         return(new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp));
     }
 }
Example #3
0
        /// <summary>
        /// Establishes a TCP connection to a SyncIOServer.
        /// Sending will fail untill handshake is completed.
        /// Bind to OnHandshake event for notify.
        /// </summary>
        /// <param name="host">IP address</param>
        /// <param name="port">Port</param>
        /// <returns></returns>
        public bool Connect(string host, int port)
        {
            var sock = NewSocket();

            try {
                sock.Connect(host, port);
                SetupConnection(sock);
                return(true);
            } catch {
                Connection = null;
                return(false);
            }
        }
Example #4
0
        private void TcpSock_OnClientConnect(BaseServerSocket sender, Socket s)
        {
            var client = new InternalSyncIOConnectedClient(s, _packager);

            client.SetID(_guidGenerator());
            client.BeginReceve(ReceveHandler);
            client.Send(cl =>
            {
                Clients.Add(cl);
                client.OnDisconnect += (c, err) => Clients.Remove(c);

                OnClientConnect?.Invoke(this, cl);//Trigger event after handshake packet has been sent.
            }, new HandshakePacket(client.ID, true));
        }
Example #5
0
 private void ReceveHandler(InternalSyncIOConnectedClient client, IPacket data)
 {
     Callbacks.Handle(this, data);
 }