[Mono-list] Udp messages
Iñigo Illán
iillan@terra.es
01 Jun 2003 18:20:09 +0200
--=-dtWrxfMi1BXY8h8cp9Iq
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
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.
--=-dtWrxfMi1BXY8h8cp9Iq
Content-Disposition: attachment; filename=client.cs
Content-Type: text/plain; name=client.cs; charset=ANSI_X3.4-1968
Content-Transfer-Encoding: 7bit
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();
}
}
--=-dtWrxfMi1BXY8h8cp9Iq
Content-Disposition: attachment; filename=server.cs
Content-Type: text/plain; name=server.cs; charset=ANSI_X3.4-1968
Content-Transfer-Encoding: 7bit
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));
}
}
--=-dtWrxfMi1BXY8h8cp9Iq--