/// <summary>
        /// Inicia una nueva conexion TCP/IP con el nombre de sesion especificado
        /// en la IP local y el puerto especificado
        /// </summary>
        /// <returns>True si todo salio bien</returns>
        public bool initializeServer(string serverName, int port)
        {
            try
            {
                this.serverName          = serverName;
                this.allClients          = new List <TgcSocketClientInfo>();
                this.connectedClients    = new List <TgcSocketClientInfo>();
                this.playerIdCounter     = 1;
                this.receivedMessages    = new Queue <TgcSocketClientRecvMesg>();
                this.newConnectedClients = new Queue <TgcSocketClientInfo>();
                this.disconnectedClients = new Queue <TgcSocketClientInfo>();

                //Crear un socket en la IP local con el puerto especificado
                serverAddress = TgcSocketServer.getHostAddress();
                IPEndPoint Ipep = new IPEndPoint(serverAddress, port);
                serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                //Hacerlo no bloqueante
                serverSocket.LingerState = new LingerOption(false, 0);
                serverSocket.Blocking    = false;
                serverSocket.Bind(Ipep);
                serverSocket.Listen(MAX_PENDING_CONNECTIONS);

                this.online = true;
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        /// <summary>
        /// Crea el modificador de Networking
        /// </summary>
        /// <param name="varName">Identificador del modifier</param>
        /// <param name="serverName">Nombre default que va a usar el servidor</param>
        /// <param name="clientName">Nombre default que va a usar cada cliente</param>
        /// <param name="port">Puerto en el cual se va a crear y buscar conexiones</param>
        public TgcNetworkingModifier(string varName, string serverName, string clientName, int port)
            : base(varName)
        {
            server = new TgcSocketServer();
            client = new TgcSocketClient();
            this.port = port;
            clientConnected = false;
            networkingControl = new TgcNetworkingModifierControl(this, serverName, clientName);
            avaliableServers = new List<TgcSocketClient.TgcAvaliableServer>();

            newConnectedClients = new Queue<TgcSocketClientInfo>();
            disconnectedClients = new Queue<TgcSocketClientInfo>(); ;

            contentPanel.Controls.Add(networkingControl);
        }
        /// <summary>
        /// Crea el modificador de Networking
        /// </summary>
        /// <param name="varName">Identificador del modifier</param>
        /// <param name="serverName">Nombre default que va a usar el servidor</param>
        /// <param name="clientName">Nombre default que va a usar cada cliente</param>
        /// <param name="port">Puerto en el cual se va a crear y buscar conexiones</param>
        public TgcNetworkingModifier(string varName, string serverName, string clientName, int port)
            : base(varName)
        {
            server            = new TgcSocketServer();
            client            = new TgcSocketClient();
            this.port         = port;
            clientConnected   = false;
            networkingControl = new TgcNetworkingModifierControl(this, serverName, clientName);
            avaliableServers  = new List <TgcSocketClient.TgcAvaliableServer>();

            newConnectedClients = new Queue <TgcSocketClientInfo>();
            disconnectedClients = new Queue <TgcSocketClientInfo>();;

            contentPanel.Controls.Add(networkingControl);
        }
Exemplo n.º 4
0
        public TgcNetworkingModifierControl(TgcNetworkingModifier modifier, string serverName, string clientName)
        {
            InitializeComponent();

            this.modifier = modifier;
            this.textBoxServerName.Text = serverName;
            this.selectedPlayerId       = -1;

            this.buttonCloseServer.Enabled      = false;
            this.buttonConnectedClients.Enabled = false;

            this.buttonDisconnect.Enabled = false;

            //Cargar IP local
            this.textBoxIp.Text = TgcSocketServer.getHostAddress().ToString();

            clientsDialog = new TgcNetworkingModifierClientsDialog(this);
            serversDialog = new TgcNetworkingModifierServersDialog(this, clientName);
        }