Toolbox.NETMF.NET.SimpleSocket

This is actually an interface, created so multiple network stacks can be used.
By default, all samples will use the .NETMF built-in network stack, with the classname "IntegratedSocket".

Currently supported networking stacks

Required methods

  • Connect(Protocol) Connects to the remote host with a specific protocol
  • Listen() Listens for a remote host
  • Close() Closes the connection
  • Send(Data) Sends a string to the remote host
  • SendBinary(Data) Sends a byte array to the remote host
  • Receive(Block) Fetches data. When block is true, it waits until data has been arrived.
  • ReceiveBinary(Length) Fetches a specific amount of bytes.
  • FeatureImplemented(Feature) Checks if a specific feature is implemented in this simple socket
  • NtpLookup() Acts like the hostname and port are for an NTP server and returns a timestamp

Required properties

  • IsConnected True when there is a connection active
  • Hostname The hostname we're connected to
  • Port The TCP port we're connected to
  • LineEnding When set, Receive() will only send data back when it contains this line ending
  • BytesAvailable Returns how many bytes are still in the incoming buffer

Sample code in C#

// Defines the socket, including the remote host and port
SimpleSocket Socket = new IntegratedSocket("www.netmftoolbox.com", 80);

// Connects to the socket
Socket.Connect();

// Does a plain HTTP request
Socket.Send("GET /helloworld/ HTTP/1.1\r\n");
Socket.Send("Host: " + Socket.Hostname + "\r\n");
Socket.Send("Connection: Close\r\n");
Socket.Send("\r\n");

// Prints all received data to the debug window, until the connection is terminated
while (Socket.IsConnected)
{
    Debug.Print(Socket.Receive());
}

// Closes down the socket
Socket.Close();

Sample code in VB

' Defines the socket, including the remote host and port
Dim Socket As SimpleSocket = New IntegratedSocket("www.netmftoolbox.com", 80)

' Connects to the socket
Socket.Connect()

' Does a plain HTTP request
Socket.Send("GET /helloworld/ HTTP/1.1" + Constants.vbCrLf)
Socket.Send("Host: " + Socket.Hostname + Constants.vbCrLf)
Socket.Send("Connection: Close" + Constants.vbCrLf)
Socket.Send(Constants.vbCrLf)

' Prints all received data to the debug window, until the connection is terminated
Do While Socket.IsConnected
    Debug.Print(Socket.Receive())
Loop

' Closes down the socket
Socket.Close()

Last edited Jun 16, 2012 at 2:02 PM by Garrcomm, version 7