Main Site Documentation

Problem Networking application with EMX


I am working with GHI’s EMX tool.
I want to communicate with time server to get the time. Can some one suggest the example. I have one example, it is working with emulator but not working with EMX tool.


A search on the forum would have yielded this:

I have this running perfectly on my Cobra.
Have fun.


Thanks for the quick reply.

I have checked the code with EMX. It is showing me error while assigning IPEndpoint at

IPEndPoint ep = new IPEndPoint(Dns.GetHostEntry(TimeServer).AddressList[0], 123);

the error message is

“An unhandled exception of type ‘System.Net.Sockets.SocketException’ occurred in Microsoft.SPOT.Net.dll”

my internet cable is connected in the ethernet port. Do i need to check another settings? How would i check that the EMX is getting internet connection or not?


Post the code you have so far (don’t forget to use the code tags)


Please find the code as under. The code is working fine with emulator but giving problem with EMX.

using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Net;
using GHIElectronics.NETMF.Net;
using System.Net;
using System.Net.Sockets;

namespace TimeServerConnection
    public class Program
        public static void Main()


        public static DateTime NTPTime(String TimeServer)
            // Find endpoint for timeserver
            IPEndPoint ep = new IPEndPoint(Dns.GetHostEntry(TimeServer).AddressList[0], 123);

            // Connect to timeserver
            Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

            // Make send/receive buffer
            byte[] ntpData = new byte[48];
            Array.Clear(ntpData, 0, 48);

            // Set protocol version
            ntpData[0] = 0x1B;

            // Send Request

            // Receive Time

            byte offsetTransmitTime = 40;

            ulong intpart = 0;
            ulong fractpart = 0;

            for (int i = 0; i <= 3; i++)
                intpart = (intpart << 8) | ntpData[offsetTransmitTime + i];

            for (int i = 4; i <= 7; i++)
                fractpart = (fractpart << 8) | ntpData[offsetTransmitTime + i];

            ulong milliseconds = (intpart * 1000 + (fractpart * 1000) / 0x100000000L);


            TimeSpan timeSpan = TimeSpan.FromTicks((long)milliseconds * TimeSpan.TicksPerMillisecond);
            DateTime dateTime = new DateTime(1900, 1, 1);
            dateTime += timeSpan;

            TimeSpan offsetAmount = TimeZone.CurrentTimeZone.GetUtcOffset(dateTime);
            DateTime networkDateTime = (dateTime + offsetAmount);

            return networkDateTime;



Has the Cobra been properly configured for a static IP address?

Make sure DNS is properly configured properly.


Thanks for the reply.

I want to know that how to configure the EMX with static IP address and DNS? Is there any code for configuration? any steps to follow?

How to check that it is configured properly?


Fire up the MFDeploy tool, select USB/EMX, then go to Target/Configuration/Network and fill in the details.


Thanks for the support. Its done. The DNS configuration was wrong and i don’t know how to configure them. Thanks all for support.


So it’s working now?

You’re welcome.