[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-libs-commits] CVS: dotgnu-base/DotGNU/Net/Sockets NetworkStream.
From: |
Peter Minten <address@hidden> |
Subject: |
[Dotgnu-libs-commits] CVS: dotgnu-base/DotGNU/Net/Sockets NetworkStream.cs,1.1.1.1,1.2 Socket.cs,1.1.1.1,1.2 |
Date: |
Sat, 27 Jul 2002 06:36:03 -0400 |
Update of /cvsroot/dotgnu-libs/dotgnu-base/DotGNU/Net/Sockets
In directory subversions:/tmp/cvs-serv12452/DotGNU/Net/Sockets
Modified Files:
NetworkStream.cs Socket.cs
Log Message:
Weekly update
Index: NetworkStream.cs
===================================================================
RCS file: /cvsroot/dotgnu-libs/dotgnu-base/DotGNU/Net/Sockets/NetworkStream.cs,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** NetworkStream.cs 21 Jul 2002 08:04:16 -0000 1.1.1.1
--- NetworkStream.cs 27 Jul 2002 10:36:01 -0000 1.2
***************
*** 24,36 ****
using System;
using System.Net.Sockets;
using DotGNU.IO;
! using DotGNU.Text;
! //We can't double inherit when both parents are classes, so we don't inherit
from
! //DotGNU Stream but reference to it when needed
! public class NetworkStream : System.Net.Sockets.Socket
{
//For the String stuff the number of chars received/send is
buffer.Length
//I keep the return type void so that programmers don't get confused
--- 24,51 ----
using System;
+ using System.Net;
using System.Net.Sockets;
+ using System.Text;
using DotGNU.IO;
! using DotGNU.Net.Sockets;
! ///<remarks>DotGNU NetworkStream, support String read/write and
! /// stream operators. Note that the alias methods (the methods referencing
! /// to ECMA compatible methods in pnetlib) are not documented, see the
! /// ECMA specs for them.</remarks>
! public class NetworkStream : System.Net.Sockets.NetworkStream, IStream
{
+ //Constructors
+
+ /// <summary>Constructor that handles the creation and connecting
+ /// of the underlying client socket.</summary>
+ /// <param name="address">The IP address to connect to.</param>
+ /// <param name="port">The port to connect to.</param>
+ public NetworkStream(IPAddress address, int port)
+ : base (this.connectSocket(address, port)) {}
+
+ //DotGNU Stuff
+
//For the String stuff the number of chars received/send is
buffer.Length
//I keep the return type void so that programmers don't get confused
***************
*** 39,44 ****
//Methods
! //Reads until no more data is available
! //Uses unicode encoding
public void Read (String buffer)
{
--- 54,60 ----
//Methods
! /// <summary>Read method using unicode,
! /// reads until no more data is available.</summary>
! /// <param name="buffer">The buffer to place the data in.</param>
public void Read (String buffer)
{
***************
*** 46,65 ****
}
! //Reads until no more data is available
! //Encoding can be specified
! public static void Read (String buffer, Encodings encoding)
{
return Stream.Read(this, buffer, encoding);
}
! //String write methods
! //Uses unicode encoding
! public static void Write(String buffer)
{
return Stream.Write(this, buffer);
}
! //Encoding can be specified
! public static void Write(String buffer, Encodings encoding)
{
return Stream.Write(this, buffer, encoding);
--- 62,87 ----
}
! /// <summary>Read method using the specified encoding,
! /// reads until no more data is available.</summary>
! /// <param name="buffer">The buffer to place the data in.</param>
! /// <param name="encoding">The encoding to use.</param>
! public void Read (String buffer, Encoding encoding)
{
return Stream.Read(this, buffer, encoding);
}
! /// <summary>Write method using unicode,
! /// writes all data in the buffer.</summary>
! /// <param name="buffer">The buffer to get the data from.</param>
! public void Write(String buffer)
{
return Stream.Write(this, buffer);
}
! /// <summary>Write method using the specified encoding,
! /// writes all data in the buffer.</summary>
! /// <param name="buffer">The buffer to get the data from.</param>
! /// <param name="encoding">The encoding to use.</param>
! public void Write(String buffer, Encoding encoding)
{
return Stream.Write(this, buffer, encoding);
***************
*** 67,79 ****
//Operators
! //The easiest way to implement these is simply copying them from
! //DotGNU Stream
! //Read operator for byte[]
public static Stream operator>> (System.IO.Stream a, byte[] b)
{
a.Read(b, 0, b.Length);
}
!
! //Read operator for String (uses unicode)
public static Stream operator>> (System.IO.Stream a, String b)
{
--- 89,107 ----
//Operators
! //The easiest way to implement these is
! //simply copying them from DotGNU Stream
!
! /// <summary>Read operator for byte[], reads until b is full.</summary>
! /// <param name="a">The stream to work on.</param>
! /// <param name="b">The buffer to put the data in.</param>
public static Stream operator>> (System.IO.Stream a, byte[] b)
{
a.Read(b, 0, b.Length);
}
!
! /// <summary>Read operator for String,
! /// reads until no more data is available.</summary>
! /// <param name="a">The stream to work on.</param>
! /// <param name="b">The buffer to put the data in.</param>
public static Stream operator>> (System.IO.Stream a, String b)
{
***************
*** 81,85 ****
}
! //Write operator for byte
public static Stream operator<< (System.IO.Stream a, byte[] b)
{
--- 109,115 ----
}
! /// <summary>Write operator for byte[].</summary>
! /// <param name="a">The stream to work on.</param>
! /// <param name="b">The buffer to get the data from.</param>
public static Stream operator<< (System.IO.Stream a, byte[] b)
{
***************
*** 87,98 ****
}
! //Write operator for String (uses unicode)
public static Stream operator<< (System.IO.Stream a, String b)
{
Write(a, b);
}
}; // class NetworkStream
-
}; // namespace DotGNU.Net.Sockets
--- 117,137 ----
}
! /// <summary>Write operator for String.</summary>
! /// <param name="a">The stream to work on.</param>
! /// <param name="b">The buffer to get the data from.</param>
public static Stream operator<< (System.IO.Stream a, String b)
{
Write(a, b);
}
+
+ //Assisting method
+ //Creates a socket and connects it
+ protected static Socket connectSocket(IPAddress address, int port)
+ {
+ DotGNU.Net.Sockets.Socket returnval = new
DotGNU.Net.Sockets.Socket();
+ returnval.Connect(new IPEndPoint(address, port));
+ }
}; // class NetworkStream
}; // namespace DotGNU.Net.Sockets
Index: Socket.cs
===================================================================
RCS file: /cvsroot/dotgnu-libs/dotgnu-base/DotGNU/Net/Sockets/Socket.cs,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** Socket.cs 21 Jul 2002 08:04:15 -0000 1.1.1.1
--- Socket.cs 27 Jul 2002 10:36:01 -0000 1.2
***************
*** 26,29 ****
--- 26,30 ----
using System.Net;
using System.Net.Sockets;
+ using System.Text;
using DotGNU.Text;
***************
*** 42,46 ****
}
! public void Bind(IPAddress address, int port)
{
Bind(new IPEndPoint(address, port));
--- 43,47 ----
}
! public void Bind(System.Net.IPAddress address, int port)
{
Bind(new IPEndPoint(address, port));
***************
*** 53,60 ****
}
! public void Connect(IPAddress address, int port)
{
Connect(new IPEndPoint(address, port));
! }
//Easy Receive methods
--- 54,61 ----
}
! public void Connect(System.Net.IPAddress address, int port)
{
Connect(new IPEndPoint(address, port));
! }
//Easy Receive methods
***************
*** 72,81 ****
}
! public void Receive(String buffer, Encodings encoding)
{
! return Receive(buffer, SocketFlags.None);
}
! public void Receive(String buffer, Encodings encoding, SocketFlags
socketFlags)
{
buffer = ""; //Clean buffer
--- 73,82 ----
}
! public void Receive(String buffer, Encoding encoding)
{
! return Receive(buffer, encoding, SocketFlags.None);
}
! public void Receive(String buffer, Encoding encoding, SocketFlags
socketFlags)
{
buffer = ""; //Clean buffer
***************
*** 83,126 ****
byte[] bbuf = new byte[1024]; //Read 1024 at a time
char[] cbuf = new char[514]; //Stay on the safe side with size
estimations
! String tbuffer;
!
do
{
int bytesreceived = Receive(bbuf, socketFlags);
-
- switch (encoding)
- {
- case Encodings.ASCII:
- ASCIIEncoding.GetChars(bbuf, 0,
bytesread, cbuf, 0);
- break;
-
- case Encodings.UTF7:
- UTF7Encoding.GetChars(bbuf, 0,
bytesread, cbuf, 0);
- break;
-
- case Encodings.UTF8:
- UTF8Encoding.GetChars(bbuf, 0,
bytesread, cbuf, 0);
- break;
! case Encodings.Unicode:
! UnicodeEncoding.GetChars(bbuf, 0,
bytesread, cbuf, 0);
break;
- case Default:
- throw new
ArgumentException(S._("InvalidEnumValue"));
- break;
- }
-
tbuffer = new String(cbuf);
!
tbuffer = tbuffer.SubString(0, charsread); //Cut off
useless chars
!
buffer += tbuffer;
!
if (bytesreceived < 1024)
return buffer;
!
! } while (true); //Infinite loop if it wasn't for that return
statement
! }
//Easy send methods
--- 84,107 ----
byte[] bbuf = new byte[1024]; //Read 1024 at a time
char[] cbuf = new char[514]; //Stay on the safe side with size
estimations
! String tbuffer;
!
do
{
int bytesreceived = Receive(bbuf, socketFlags);
! encoding.GetChars(bbuf, 0, bytesread, cbuf, 0);
break;
tbuffer = new String(cbuf);
!
tbuffer = tbuffer.SubString(0, charsread); //Cut off
useless chars
!
buffer += tbuffer;
!
if (bytesreceived < 1024)
return buffer;
!
! } while (true); //Infinite loop if it wasn't for that return
statement
! }
//Easy send methods
***************
*** 135,167 ****
}
! public void Send(String buffer, Encodings encoding)
{
! return Send(buffer, SocketFlags.None);
}
! public void Send(String buffer, Encodings encoding, SocketFlags
socketFlags)
{
! switch (encoding)
! {
! case Encodings.ASCII:
! Send(ASCIIEncoding.GetBytes(buffer),
socketFlags);
! return;
!
! case Encodings.UTF7:
! Send(UTF7Encoding.GetBytes(buffer),
socketFlags);
! return;
!
! case Encodings.UTF8:
! Send(UTF8Encoding.GetBytes(buffer),
socketFlags);
! return;
!
! case Encodings.Unicode:
! Send(UnicodeEncoding.GetBytes(buffer),
socketFlags);
! return;
!
! case Default:
! throw new
ArgumentException(S._("InvalidEnumValue"));
! break;
! }
}
--- 116,127 ----
}
! public void Send(String buffer, Encoding encoding)
{
! return Send(buffer, encoding, SocketFlags.None);
}
! public void Send(String buffer, Encoding encoding, SocketFlags
socketFlags)
{
! return Send(encoding.GetBytes(buffer), socketFlags);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-libs-commits] CVS: dotgnu-base/DotGNU/Net/Sockets NetworkStream.cs,1.1.1.1,1.2 Socket.cs,1.1.1.1,1.2,
Peter Minten <address@hidden> <=
- Prev by Date:
[Dotgnu-libs-commits] CVS: dotgnu-base ChangeLog,1.1.1.1,1.2 compile.sh,1.1.1.1,1.2
- Next by Date:
[Dotgnu-libs-commits] CVS: dotgnu-base/DotGNU/IO FileStream.cs,NONE,1.1 IStream.cs,NONE,1.1 Stream.cs,1.1.1.1,1.2
- Previous by thread:
[Dotgnu-libs-commits] CVS: dotgnu-base ChangeLog,1.1.1.1,1.2 compile.sh,1.1.1.1,1.2
- Next by thread:
[Dotgnu-libs-commits] CVS: dotgnu-base/DotGNU/IO FileStream.cs,NONE,1.1 IStream.cs,NONE,1.1 Stream.cs,1.1.1.1,1.2
- Index(es):