Skip to content

Instantly share code, notes, and snippets.

@noqisofon
Created November 11, 2010 02:46
Show Gist options
  • Save noqisofon/671900 to your computer and use it in GitHub Desktop.
Save noqisofon/671900 to your computer and use it in GitHub Desktop.
silicone(架空のオレオレ言語)で書かれた、UDPSocket クラスを使ったデモ。
using std;
using std.io;
using std.text;
using net.socket;
let port : int = 52292;
let udp_sender : UDPSocket = new UDPSocket( port );
try {
udp_sender.connect( "www.const.com", port );
let send_bytes : byte[] = Encoding.ASCII.encodeFromString( "Is anybody there?" );
udp_sender.send( send_bytes, send_bytes.length );
let remote_any_endpoint : IPEndPoint = new IPEndPoint( IPAddress.ANY, 0 );
let receive_bytes : byte[] = udp_sender.receive( remote_any_endpoint );
let result_data : string = Encoding.ASCII.decodeFromBytes( receive_bytes );
console.printf( "this is the message you received: %s\n", result_data.toString() );
console.printf( "this message was sent from %s on their port number\n",
remote_any_endpoint.address.toString(),
remote_any_endpoint.port.toString()
);
} catch ( e : Exception ) {
console.printf( e.toString() );
} finalize {
udp_sender.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment