Skip to content

Instantly share code, notes, and snippets.

@cwschroeder
Created May 13, 2012 08:18
Show Gist options
  • Save cwschroeder/2686911 to your computer and use it in GitHub Desktop.
Save cwschroeder/2686911 to your computer and use it in GitHub Desktop.
Netmf mountaineer connect problem
using System;
using Microsoft.SPOT;
namespace MFTestApp
{
using System.Net;
using System.Net.Sockets;
using System.Threading;
using MFCommonExtension.Strings;
using Microsoft.SPOT.Net.NetworkInformation;
public class Program
{
public static void Main()
{
Debug.Print(StringUtil.Format("APP started {0}.", DateTime.Now));
var netinterfaces = NetworkInterface.GetAllNetworkInterfaces();
var eth = netinterfaces[0];
eth.PhysicalAddress = new byte[] {0x00,0xFF,0xC3,0x1E,0x77,0x01};
eth.EnableStaticIP("192.168.2.44", "255.255.255.0", "192.168.2.1");
//eth.EnableDhcp();
Debug.Print("Network interface configured.");
Debug.Print(StringUtil.Format("IP {0}, NM {1}, GW {2}.", eth.IPAddress, eth.SubnetMask, eth.GatewayAddress));
var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
//IPEndPoint relayEndpoint = new IPEndPoint(IPAddress.Parse("78.46.63.147"), 9090);
IPEndPoint relayEndpoint = new IPEndPoint(IPAddress.Parse("192.168.2.1"), 80);
try
{
socket.Connect(relayEndpoint);
}
catch (Exception ex)
{
Debug.Print(StringUtil.Format("Connect error {0}. ST {1}.", ex.Message, ex.StackTrace));
}
while (true)
{
try
{
if (socket.Poll(100, SelectMode.SelectRead))
{
Debug.Print("Socket connected.");
}
}
catch (Exception ex)
{
Debug.Print("Socket not connected.");
}
Thread.Sleep(500);
}
Debug.Print(
Resources.GetString(Resources.StringResources.String1));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment