Foros del Web » Programación para mayores de 30 ;) » .NET »

Cliente -Servidor.

Estas en el tema de Cliente -Servidor. en el foro de .NET en Foros del Web. Hola: Tengo hecho algo de Cliente-Servidor muy básico. Me gustaría saber que si el PC1 se conecta al PC2, envía al PC1 un mensaje que ...
  #1 (permalink)  
Antiguo 22/03/2009, 02:05
 
Fecha de Ingreso: mayo-2007
Ubicación: PIC-16F84A
Mensajes: 727
Antigüedad: 17 años
Puntos: 8
Cliente -Servidor.

Hola:

Tengo hecho algo de Cliente-Servidor muy básico. Me gustaría saber que si el PC1 se conecta al PC2, envía al PC1 un mensaje que advierta si su conexión ha sido un éxito y que se mantenga en línea como el messenger. Cuando PC1 cierra la conexión mediante un buttón o botón, el PC2 muestra un mensaje indicando su conexión.

NOTA: Los botones de Control,por ahora no hablamos de ellos y aún no es funcional.

DESCARGAR


PC1-Cliente:
Código:
using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
using System.IO; 
using System.Net; 
using System.Net.Sockets; 
 
namespace PC1_Cliente 
{ 
    public partial class Form_principal : Form 
    { 
        public Form_principal() 
        { 
            InitializeComponent(); 
        } 
 
        private void button_Conectar_Click(object sender, EventArgs e) 
        { 
            UdpClient udpClient = new UdpClient(); 
            udpClient.Connect(textBox1.Text, 8888); 
            Byte[] sendBytes = Encoding.ASCII.GetBytes(textBox2.Text); 
            udpClient.Send(sendBytes, sendBytes.Length); 
        } 
    } 
}
PC2-Servidor:
Código:
using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
using System.IO; 
using System.IO.Ports; 
using System.Net; 
using System.Net.Sockets; 
using System.Threading; 
 
namespace PC2_Servidor 
{ 
    public partial class Form1 : Form 
    { 
        public Form1() 
        { 
            InitializeComponent(); 
            if (!serialPort1.IsOpen) 
            { 
                try 
                { 
                    serialPort1.Open(); 
                } 
                catch (System.Exception ex) 
                { 
                    MessageBox.Show(ex.ToString()); 
                } 
            } 
        } 
        public void serverThread() 
        { 
        UdpClient udpClient = new UdpClient(8888); 
        while(true) 
        { 
        IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0); 
        Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint); 
        string returnData = Encoding.ASCII.GetString(receiveBytes); 
        lbConnections.Items.Add(RemoteIpEndPoint.Address.ToString() + ":" + returnData.ToString() ); 
        } 
        } 
        private void Form1_Load(object sender, EventArgs e) 
        { 
            Thread thdUDPServer = new Thread(new 
            ThreadStart(serverThread)); 
            thdUDPServer.Start(); 
        } 
    } 
}
Un cordial saludo.
__________________
Meta Shell, VERSIÓN 1.2.2
Descargar
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 10:55.