diff options
author | fcolin | 2007-02-01 09:51:10 +0000 |
---|---|---|
committer | fcolin | 2007-02-01 09:51:10 +0000 |
commit | 7846656a1d1fc7d4e1b3bb37a8a38d021289808a (patch) | |
tree | 07887700b8d3306bb22322c4c65b17599d2e50a9 /CSharp | |
parent | fbb6c31c7efbab72f48d2691bd20acaa866f9472 (diff) | |
download | ivy-csharp-7846656a1d1fc7d4e1b3bb37a8a38d021289808a.zip ivy-csharp-7846656a1d1fc7d4e1b3bb37a8a38d021289808a.tar.gz ivy-csharp-7846656a1d1fc7d4e1b3bb37a8a38d021289808a.tar.bz2 ivy-csharp-7846656a1d1fc7d4e1b3bb37a8a38d021289808a.tar.xz |
Utilisateur : Fcolin Date : 29/11/05 Heure : 16:23 Créé Commentaire: (vss 1)
Diffstat (limited to 'CSharp')
-rw-r--r-- | CSharp/Ivy/Ivy/IvyUDPStreamV4.cs | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/CSharp/Ivy/Ivy/IvyUDPStreamV4.cs b/CSharp/Ivy/Ivy/IvyUDPStreamV4.cs new file mode 100644 index 0000000..d5319c8 --- /dev/null +++ b/CSharp/Ivy/Ivy/IvyUDPStreamV4.cs @@ -0,0 +1,65 @@ +using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Net;
+using System.Net.Sockets;
+using System.IO;
+
+namespace IvyBus
+{
+ class IvyUDPStream
+ {
+ Socket socket;
+ BinaryReader input;
+ BinaryWriter output;
+ byte[] buffer;
+ MemoryStream out_stream;
+ MemoryStream in_stream;
+
+ public IvyUDPStream(Socket _socket)
+ {
+ socket = _socket;
+ buffer = new byte[4096];
+ in_stream = new MemoryStream(buffer);
+ input = new BinaryReader( in_stream,Encoding.ASCII);
+ out_stream = new MemoryStream();
+ output = new BinaryWriter(out_stream, Encoding.ASCII);
+ }
+
+ internal void receiveMsg(out IPEndPoint remote, out int version, out int 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;
+ version = (ushort)IPAddress.NetworkToHostOrder((short)input.ReadUInt16());
+ port = (ushort)IPAddress.NetworkToHostOrder((short)input.ReadUInt16());
+ int lenAppId = (ushort)IPAddress.NetworkToHostOrder((short)input.ReadUInt16());
+ appId = new String(input.ReadChars(lenAppId));
+ int lenAppNameId = (ushort)IPAddress.NetworkToHostOrder((short)input.ReadUInt16());
+ appName = new String(input.ReadChars(lenAppNameId));
+
+ }
+
+ internal void sendMsg(IPEndPoint EPhost, int port, string appId, string appName)
+ {
+ output.Write((ushort)IPAddress.HostToNetworkOrder((short)(Ivy.PROCOCOLVERSION)));
+ output.Write((ushort)IPAddress.HostToNetworkOrder((short)port));
+ output.Write((ushort)IPAddress.HostToNetworkOrder((short)appId.Length));
+ output.Write(appId.ToCharArray());
+ output.Write((ushort)IPAddress.HostToNetworkOrder((short)appName.Length));
+ output.Write(appName.ToCharArray());
+ output.Flush();
+
+ byte[] hellob = out_stream.GetBuffer();
+ socket.SendTo(hellob, (int)out_stream.Length, 0, EPhost); // notifies our arrival on each domain: protocol version + port
+ }
+ internal void Close()
+ {
+ socket.Close();
+ }
+ }
+}
|