diff options
author | fcolin | 2007-02-01 10:02:42 +0000 |
---|---|---|
committer | fcolin | 2007-02-01 10:02:42 +0000 |
commit | ef27af2c51c50ff65746e142262db0b50d6cb994 (patch) | |
tree | 1828b727d4d880f6d88c4b1921012eb9b0b0561f /CSharp/Ivy/IvyPPC | |
parent | ef6c11f73f7d20e03d208616a0e19bef710bd2b1 (diff) | |
download | ivy-csharp-ef27af2c51c50ff65746e142262db0b50d6cb994.zip ivy-csharp-ef27af2c51c50ff65746e142262db0b50d6cb994.tar.gz ivy-csharp-ef27af2c51c50ff65746e142262db0b50d6cb994.tar.bz2 ivy-csharp-ef27af2c51c50ff65746e142262db0b50d6cb994.tar.xz |
Utilisateur : Fcolin Date : 1/12/05 Heure : 17:47 Créé Commentaire: (vss 1)
Diffstat (limited to 'CSharp/Ivy/IvyPPC')
-rw-r--r-- | CSharp/Ivy/IvyPPC/IvyUDPStreamV3.cs | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/CSharp/Ivy/IvyPPC/IvyUDPStreamV3.cs b/CSharp/Ivy/IvyPPC/IvyUDPStreamV3.cs new file mode 100644 index 0000000..0711f07 --- /dev/null +++ b/CSharp/Ivy/IvyPPC/IvyUDPStreamV3.cs @@ -0,0 +1,76 @@ +using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Net;
+using System.Net.Sockets;
+using System.IO;
+
+namespace IvyBus
+{
+ class IvyUDPStreamV3
+ {
+ Socket socket;
+ StreamReader input;
+ StreamWriter output;
+ byte[] buffer;
+ MemoryStream out_stream;
+ MemoryStream in_stream;
+
+ /// the protocol version number
+ internal const int PROCOCOLVERSION = 3;
+
+ public IvyUDPStreamV3(Socket _socket)
+ {
+ socket = _socket;
+ buffer = new byte[4096];
+ in_stream = new MemoryStream(buffer);
+ input = new StreamReader(in_stream, Encoding.ASCII);
+ out_stream = new MemoryStream();
+ output = new StreamWriter(out_stream, Encoding.ASCII);
+ }
+ /*
+ * message Syntax:
+ * this is a binary formated message use of network representation
+ *
+ * message Format:
+ protocol_version, TCP server port , lenAppId, appId, lenAppNameId, appName
+ */
+
+ 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 = input.ReadUInt16();
+ port = input.ReadUInt16();
+ int lenAppId = input.ReadUInt16();
+ appId = input.ReadChars(lenAppId);
+ int lenAppName = input.ReadUInt16();
+ appName = new String(input.ReadChars(lenAppName));
+
+ }
+
+ internal void sendMsg(IPEndPoint EPhost, int port, string appId, string appName)
+ {
+ String.Format()
+ output.Write((ushort)IPAddress.HostToNetworkOrder((short)(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);
+ }
+ internal void Close()
+ {
+ socket.Close();
+ }
+ }
+}
|