Beispiel #1
0
        public Socket EstablishConnection()
        {
            ConnectionEstablishmentStrategy.Run();
            if (!ConnectionEstablishmentStrategy.IsRunning)
            {
                return(null);
            }
            ConnectionEstablishmentStrategy.Stop();
            remoteEndPointFactory = new EndPointFactory(ConnectionEstablishmentStrategy.RemotePort);
            Socket clientSocket = null;

            if (ConnectionEstablishmentStrategy.IsLocalHostServer)
            {
                if (ConnectionEstablishmentStrategy.MultipleClients)
                {
                    ConnectionEstablishmentStrategy.Role = TcpRole.Server;
                    new Thread((ConnectionEstablishmentStrategy.Run)).Start();
                    new Thread(() => Server.Current.Start(serverSocket)).Start();
                    clientSocket = Connect(localEndPointFactory.Create(IPAddress.Loopback));
                }
                else
                {
                    clientSocket = AcceptConnection();
                }
            }
            else if (ConnectionEstablishmentStrategy.ServerIPAddress != null)
            {
                clientSocket = Connect(ConnectionEstablishmentStrategy.ServerIPAddress);
            }
            return(clientSocket);
        }
Beispiel #2
0
 public Connector(IConnectionEstablishmentStrategy connectionEstablishmentStrategy)
 {
     this.ConnectionEstablishmentStrategy = connectionEstablishmentStrategy;
     localEndPointFactory = new EndPointFactory(connectionEstablishmentStrategy.LocalPort);
     serverSocket.Bind(localEndPointFactory.Create(IPAddress.Any));
     SetupSocket(serverSocket);
     serverSocket.Listen(10);
 }