Potreboval by som pomôcť s nasledujúcim kódom. Jeho účelom je aby po sieti poslal spravu a po jej odoslaní čakal kým nepošle správu niekto iný. Lenže program sa zasekne na príjmami aj keď niekto správu odošle.
Ďakujem za pomoc.
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
namespace UDP_TCP_chat
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
udpPosielanie();
}
public void udpPosielanie()
{
UdpClient udp = new UdpClient();
udp.EnableBroadcast = true;
IPEndPoint groupEP = new IPEndPoint(IPAddress.Broadcast, 54319);
string str4 = "Is anyone out there?";
byte[] sendBytes4 = Encoding.ASCII.GetBytes(str4);
udp.Send(sendBytes4, sendBytes4.Length, groupEP);
//receive
IPEndPoint receiveEndPoint = new IPEndPoint(IPAddress.Any, 54319);
byte[] receiveBytes = udp.Receive( ref receiveEndPoint);
string returnData = Encoding.ASCII.GetString(receiveBytes);
System.Diagnostics.Debug.WriteLine(returnData);
}
}
}
cele to mas nejake divne ked take nieco robis potrebujes serversocket, ktory tam nikde nevidim a navyse Ti to musi bezat v cykle ( alebo este lepsie v threade ). a ako vyzera klientska aplikacia? Alebo je hento clientska aplikacia a nemas ziadnu serverovu?
Ono je to oboje ma to fungovať cez lan a každá apklikácia bude client aj server. Celé by to malo vyzerať tak, že cez UDP budem vysielať žiadosť do siete na odoslanie ip. Po priati ip si ju uloží a nadviaže spojenie pomocou TCP protokolu.