I've been trying to run a simple program on mono that sends a Udp
datagram I can't make it work. I don't know if I have done something
wrong or maybe there is some bug on mono?
Thanks in advance.
using System;
using System.Net;
using System.Net.Sockets;
class client {
static UdpClient udpc;
static byte[] mensaje = { 0x4D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65};
public static void Main() {
udpc = new UdpClient();
udpc.Connect("192.168.0.1", 30000);
udpc.Send (client.mensaje, client.mensaje.Length);
udpc.Close();
}
}
using System;
using System.Net;
using System.Net.Sockets;
public class server
{
public static EndPoint rp;
public static Socket sock;
public static IPHostEntry localhost;
public static IPEndPoint localIpEndPoint;
public static Byte[] msg = new Byte[256];
public static void Main ()
{
sock = new Socket (AddressFamily.InterNetwork, SocketType.Dgram,
ProtocolType.Udp);
server.localhost = Dns.GetHostByName(Dns.GetHostName());
try
{
server.localIpEndPoint = new
IPEndPoint(server.localhost.AddressList[0], 30000);
sock.Bind(localIpEndPoint);
}
catch(Exception ex)
{
Console.WriteLine("Exception thrown: {0}", ex.Message);
}
server.rp = new IPEndPoint(IPAddress.Any, 0);
server.sock.Receive (server.msg);
Console.WriteLine (System.Text.Encoding.ASCII.GetString(server.msg));
}
}