elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: (TUTORIAL) Aprende a emular Sentinel Dongle By Yapis


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  Cliente -Servidor.
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Cliente -Servidor.  (Leído 3,518 veces)
Meta


Desconectado Desconectado

Mensajes: 3.439



Ver Perfil WWW
Cliente -Servidor.
« en: 22 Marzo 2009, 09:12 am »

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.


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Cliente - Servidor
Ingeniería Inversa
karnank440 0 1,585 Último mensaje 18 Enero 2013, 07:05 am
por karnank440
Servidor y Cliente UDP - echo test
Java
BatchianoISpyxolo 1 3,248 Último mensaje 8 Febrero 2013, 14:03 pm
por BatchianoISpyxolo
Imagenes de Cliente-Servidor
Programación Visual Basic
GranDestello 7 4,694 Último mensaje 18 Enero 2014, 18:04 pm
por GranDestello
CLIENTE Y SERVIDOR FUERA DE RED VB.NET
Programación Visual Basic
LordOz 2 2,203 Último mensaje 26 Septiembre 2014, 22:13 pm
por LordOz
[Solucionado] Programando socke cliente y servidor en C
Programación C/C++
r1ghtz0 8 3,984 Último mensaje 16 Octubre 2014, 19:08 pm
por r1ghtz0
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines