![]() |
![]() |
| Paypal | FTP | CCD | Buscar | Trucos | Trabajo | Foros |
|
|||||||
| Registrarse | FAQ | Miembros | Calendario | Guía de estilo | Temas de Hoy |
![]() |
|
|
Herramientas | Buscar en Tema | Desplegado |
|
#1
|
|||
|
|||
|
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);
}
}
}
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();
}
}
}
__________________
http://electronica-pic.blogspot.com....n-arduino.html Manuales de electrónica general, PIC y Arduino. |
|
#3
|
||||
|
||||
|
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] |
![]() |
|
|
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 |
|