/// <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); } }
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); }