From 09cac7c22c022e9fce679cf03bc389121b033eea Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 09:50:48 +0000 Subject: Utilisateur : Fcolin Date : 19/12/05 Heure : 16:54 Créé Commentaire: (vss 1) --- CSharp/Ivy/Ivy/IvyUDPStream.cs | 64 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 CSharp/Ivy/Ivy/IvyUDPStream.cs (limited to 'CSharp') diff --git a/CSharp/Ivy/Ivy/IvyUDPStream.cs b/CSharp/Ivy/Ivy/IvyUDPStream.cs new file mode 100644 index 0000000..feecba0 --- /dev/null +++ b/CSharp/Ivy/Ivy/IvyUDPStream.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Net; +using System.Net.Sockets; +using System.IO; + +namespace IvyBus +{ + abstract class IvyUDPStream + { + Socket socket; + byte[] buffer; + + protected MemoryStream out_stream; + protected MemoryStream in_stream; + + ushort protocol_version; + + public ushort ProtocolVersion + { + get { return protocol_version; } + } + + public IvyUDPStream(Socket _socket, ushort protocol) + { + socket = _socket; + buffer = new byte[4096]; + in_stream = new MemoryStream(buffer); + out_stream = new MemoryStream(); + protocol_version = protocol; + } + internal void Close() + { + in_stream.Close(); + out_stream.Close(); + socket.Close(); + } + internal void receiveMsg(out IPEndPoint remote, out ushort version, out ushort port, out string appId, out string appName) + { + int len; + IPEndPoint remoteEP = new IPEndPoint(IPAddress.Any, 0); + EndPoint tempRemoteEP = (EndPoint)remoteEP; + remoteEP = null; + len = socket.ReceiveFrom(buffer, ref tempRemoteEP); + remote = (IPEndPoint)tempRemoteEP; + in_stream.Position = 0; + in_stream.SetLength(len); + //Call Deserialization + Deserialize( out version, out port, out appId, out appName ); + } + internal void sendMsg(IPEndPoint EPhost, ushort port, string appId, string appName) + { + // Call Serialisation + Serialize(port, appId, appName); + + byte[] hellob = out_stream.GetBuffer(); + socket.SendTo(hellob, (int)out_stream.Length, 0, EPhost); + } + abstract internal void Serialize(ushort port, string appId, string appName); + abstract internal void Deserialize(out ushort version, out ushort port, out string appId, out string appName); + + } +} -- cgit v1.1