PowerTCP Mail for .NET
Receive() Method
See Also  Example Send comments on this topic.
Dart.PowerTCP.Mail Namespace > Tcp Class > Receive Method : Receive() Method




Receive data from the host.

Syntax

Visual Basic (Declaration) 
<DescriptionAttribute("Receives data into a dynamically instantiated buffer before returning it as an ASCII string.")>
Public Overloads Function Receive() As Segment
Visual Basic (Usage)Copy Code
Dim instance As Tcp
Dim value As Segment
 
value = instance.Receive()
C# 
[DescriptionAttribute("Receives data into a dynamically instantiated buffer before returning it as an ASCII string.")]
public Segment Receive()
Managed Extensions for C++ 
[DescriptionAttribute("Receives data into a dynamically instantiated buffer before returning it as an ASCII string.")]
public: Segment* Receive(); 
C++/CLI 
[DescriptionAttribute("Receives data into a dynamically instantiated buffer before returning it as an ASCII string.")]
public:
Segment^ Receive(); 

Return Value

A Segment object encapsulating the data received.

Exceptions

ExceptionDescription
System.IO.IOExceptionThe stream is not Readable.
System.ArgumentNullExceptionbuffer is null.
System.ArgumentOutOfRangeExceptionoffset or count is less than 0.
System.ArgumentExceptionoffset + count is greater than the length of buffer.
System.Net.Sockets.SocketExceptionThe socket is not connected.

Example

The following example demonstrates blocking operations using the Tcp component.
Visual BasicCopy Code
Private Sub TcpDemo()
   ' The following code assumes that good responses are always received from
   ' the server. More robust code should check each response and handle appropriately.

   ' Connect to Echo Server
   Tcp1.Connect("myEchoServer", 7)

   ' Send some data
   Tcp1.Send("Hello Server!" + vbCrLf)

   ' Get response from the server
   Dim seg As Segment = Tcp1.Receive()
   Debug.WriteLine(seg.ToString())

   ' Send more data
   Tcp1.Send("You are a swell host" + vbCrLf)

   ' Get response from the server
   seg = Tcp1.Receive()
   Debug.WriteLine(seg.ToString())
   
   'Close the connection
   Tcp1.Close()
End Sub
C#Copy Code
private void TcpDemo()
{
   // The following code assumes that good responses are always received from
   // the server. More robust code should check each response and handle appropriately.

   // Connect to Echo Server
   tcp1.Connect("myEchoServer", 7);

   // Send some data
   tcp1.Send("Hello Server!\r\n");

   // Get response from the server
   Segment seg = tcp1.Receive();
   Debug.WriteLine(seg.ToString());

   // Send more data
   tcp1.Send("You are a swell host\r\n");

   // Get response from the server
   seg = tcp1.Receive();
   Debug.WriteLine(seg.ToString());
   
   //Close the connection
   tcp1.Close();
}

Remarks

After connecting, data can be received using the Tcp.Recieve method. All Tcp.Receive methods return a Segment object, encapsulating the data received. In order to access the data, simply access the properties of the Segment object returned such as Segment.Buffer (to access the data in a byte array) or Segment.ToString (to access the data as a string).

If the amount of data received from the server exceeds Tcp.ReceiveBufferSize, the Tcp.Receive method will have to be called multiple times until the socket closes.

This method is functionally equivalent to Tcp.Stream.Write().

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

Documentation Version 3.2
© 2010 Dart Communications. All Rights Reserved.