Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros entornos y lenguajes > .NET
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 22-03-2009
REHome REHome is offline
Miembro
 
Registrado: jul 2003
Ubicación: España
Posts: 454
Poder: 21
REHome Va por buen camino
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.
__________________
http://electronica-pic.blogspot.com....n-arduino.html Manuales de electrónica general, PIC y Arduino.
Responder Con Cita
  #2  
Antiguo 23-03-2009
Avatar de cHackAll
[cHackAll] cHackAll is offline
Baneado?
 
Registrado: oct 2006
Posts: 2.159
Poder: 20
cHackAll Va por buen camino
No entiendo qué necesitas?

PD; si es una aplicacion LAN, por qué no usas el protocolo TCP ?
__________________
RTFM > STFW > Foro > Truco > Post > cHackAll > KeBugCheckEx
Responder Con Cita
  #3  
Antiguo 24-03-2009
Avatar de Crandel
[Crandel] Crandel is offline
Miembro Premium
 
Registrado: may 2003
Ubicación: Parana, Argentina
Posts: 1.475
Poder: 23
Crandel Va por buen camino
Si estas interesado en la conexión creo que deberias utilizar el protocolo TCP.

Por otro lado veo que estas agregando texto a un componente grafico (lbConnections) desde una Thread. Eso te va a dar error casi seguro.

Para evitar este problema debes utilizar el método Invoke del formulario para sincronizar los hilos.
__________________
[Crandel]
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Cliente / Servidor carlosro_ec C++ Builder 2 11-12-2005 17:06:14
cliente/servidor alfil123 Conexión con bases de datos 1 01-12-2005 16:40:42
cliente servidor dmagui Conexión con bases de datos 4 21-10-2005 20:07:16
Cliente-servidor joHn je@N Varios 1 05-06-2005 00:26:06
Cliente - Servidor Sotrono Internet 5 16-04-2004 05:50:35


La franja horaria es GMT +2. Ahora son las 18:08:11.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi