Skip to content

Instantly share code, notes, and snippets.

@txdv
Created July 6, 2011 12:00
Show Gist options
  • Save txdv/1067063 to your computer and use it in GitHub Desktop.
Save txdv/1067063 to your computer and use it in GitHub Desktop.
Manos Udp proposal
using System;
using System.Text;
using Manos.IO;
namespace Test
{
public static class ByteBufferExtensions
{
public static string GetString(this ByteBuffer buffer, Encoding encoding)
{
return encoding.GetString(buffer.Bytes, buffer.Position, buffer.Length);
}
}
class MainClass
{
public static void Main (string[] args)
{
Context context = Context.Create();
var hello = new UdpPacket() {
Address = "127.0.0.1",
Port = 1080,
Buffer = new ByteBuffer(Encoding.ASCII.GetBytes("Hello World"))
};
UdpSocket sender = context.CreateUdpSocket(AddressFamily.InterNetwork);
sender.Bind("0.0.0.0", 1230);
UdpSocket socket = context.CreateUdpSocket(AddressFamily.InterNetwork);
socket.Bind("127.0.0.1", 1080);
socket.Receive(delegate (UdpPacket packet) {
Console.WriteLine ("{0}:{1}: {2}",
packet.Address,
packet.Port,
packet.Buffer.GetString(Encoding.ASCII));
sender.Send(hello);
});
sender.Send(hello);
context.Start();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment