Here is an example on how to get started with Native TCP/IP made for WIZnet W5100:
First, If you are using one of the Ethernet shields made for arduino, you need to make a small hardware issue fix, for more reliable performance:
The reset signal on these shields are not connected to any of the digital IO which is wrong. To solve this you have to bend out the reset pin on the shield and connect it to one of the available IOs as you see in the picture.
I connected the the Ethernet shield’s reset signal to Di9.
Second, here is a simple example that I took from NETMF SDK examples (SocketServer example)and edited it to got it working with our library for W5100. only minor addition is needed as you can see because the new libraries made to be compatible with the original System.Net libraries.
Note: You need to add the following libraries (assemblies) GHIElectronics.NETMF.W5100 and Microsoft.SPOT.Hardware.
Do NOT add the original Socket Microsoft Libraries!
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Net;
using GHIElectronics.NETMF.Net.Sockets;
using GHIElectronics.NETMF.Net.NetworkInformation;
using System.Text;
using Socket = GHIElectronics.NETMF.Net.Sockets.Socket;
namespace FEZ_Application1
{
public static class MySocketServer
{
public static void Main()
{
const Int32 c_port = 80;
byte[] ip = { 192, 168, 0, 200 };
byte[] subnet = { 255, 255, 255, 0 };
byte[] gateway = { 192, 168, 0, 1 };
byte[] mac = { 43, 185, 44, 2, 206, 127 };
WIZnet_W5100.Enable(SPI.SPI_module.SPI1, (Cpu.Pin)FEZ_Pin.Digital.Di10, (Cpu.Pin)FEZ_Pin.Digital.Di9);
NetworkInterface.EnableStaticIP(ip, subnet, gateway, mac);
NetworkInterface.EnableStaticDns(new byte[]{192,168,0,1});
Socket server = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, c_port);
server.Bind(localEndPoint);
server.Listen(1);//Int32.MaxValue);
while (true)
{
// Wait for a client to connect.
Socket clientSocket = server.Accept();
// Process the client request. true means asynchronous.
new ProcessClientRequest(clientSocket, true);
}
}
/// <summary>
/// Processes a client request.
/// </summary>
internal sealed class ProcessClientRequest
{
private Socket m_clientSocket;
/// <summary>
/// The constructor calls another method to handle the request, but can
/// optionally do so in a new thread.
/// </summary>
/// <param name="clientSocket"></param>
/// <param name="asynchronously"></param>
public ProcessClientRequest(Socket clientSocket, Boolean asynchronously)
{
m_clientSocket = clientSocket;
if (asynchronously)
// Spawn a new thread to handle the request.
new Thread(ProcessRequest).Start();
else ProcessRequest();
}
/// <summary>
/// Processes the request.
/// </summary>
private void ProcessRequest()
{
const Int32 c_microsecondsPerSecond = 1000000;
// 'using' ensures that the client's socket gets closed.
using (m_clientSocket)
{
// Wait for the client request to start to arrive.
Byte[] buffer = new Byte[1024];
if (m_clientSocket.Poll(5 * c_microsecondsPerSecond,
SelectMode.SelectRead))
{
// If 0 bytes in buffer, then the connection has been closed,
// reset, or terminated.
if (m_clientSocket.Available == 0)
return;
// Read the first chunk of the request (we don't actually do
// anything with it).
Int32 bytesRead = m_clientSocket.Receive(buffer,
m_clientSocket.Available, SocketFlags.None);
// Return a static HTML document to the client.
String s =
"HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=utf-8\r\n\r\n<html><head><title>.NET Micro Framework Web Server on USBizi Chipset </title></head>" +
"<body><bold><a href=\"http://www.tinyclr.com/\">Learn more about the .NET Micro Framework with FEZ by clicking here</a></bold></body></html>";
m_clientSocket.Send(Encoding.UTF8.GetBytes(s));
}
}
}
}
}
}
Now you have a simple web server 8)