/// <summary> /// Cuando el cliente se conecto finalmente con el server /// </summary> public void clientConnectedToServer(TgcSocketServerInfo serverInfo, int playerId) { buttonJoinServer.Enabled = false; buttonDisconnect.Enabled = true; textBoxCurrentServer.Text = serverInfo.Name; textBoxCurrentServer.BackColor = Color.Green; textBoxPlayerId.Text = playerId.ToString(); textBoxServerIp.Text = modifier.Client.ServerInfo.Address.ToString(); }
/// <summary> /// Se conecta a un nuevo servidor. Pero todavía no lo toma como definitivo hasta /// que no se hace la selección final. /// </summary> /// <param name="ip">IP del server</param> /// <param name="port">Puerto del server</param> /// <returns>True si todo salio bien</returns> public bool connect(string ip, int port) { try { //Conectar con el server, en forma no bloqueante var address = IPAddress.Parse(ip); var Ipep = new IPEndPoint(address, port); clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); clientSocket.Connect(Ipep); clientSocket.Blocking = false; ServerInfo = new TgcSocketServerInfo(address, port); //Enviar mensaje de Handshake clientSocket.Send(Encoding.ASCII.GetBytes(CLIENT_HANDSHAKE)); Status = TgcSocketClientInfo.ClientStatus.HandshakePending; return(true); } catch (Exception) { return(false); } }