Networking socket issue

i need to deal with a socket connection issue to various server located on the internet (not tls)

from several attempts, most of the time the socket connection can’t be established and runs in a defined timeout
(connection attempts at the same time from a machine on the same network as the SC20260 works without issues and delays)

it only takes a few milliseconds if the connection can be established successfully

i cant reproduce this behavior trying to connect to a host on LAN

sample to test:
(It contains the Built-in Ethernet code from docs and is configured for SC20260)
TestProject

Have you tried WiFi and ethernet?

no, only built in ethernet

Added to GitHub

1 Like

Can you please post your project again.

it says: " This item might not exist or is no longer available".

Thanks

complicated to fill done into 10 chars

Did you mean done? I still see same message.

https://1drv.ms/u/s!AmeIIBQl_WQUntZCk8mRPpG7KqJhtQ

got it. Thankls

1 Like

Hello @Austrian_Dude, nice to see you here back again.
My experience (I didn’t try the latest versions) is, that dns doesnt always resolve the Ip_address of an url on the first try.

I always try a few times like

 IPAddress[] address = null;
 for (int i = 0; i < 3; i++)
 {
    try
        {
            address = System.Net.Dns.GetHostEntry(pTimeServer_1).AddressList;
        }
        catch { };
        if (address != null)
        {
           break;
    }	
 }

thank you @RoSchmi :heart_eyes:

its not a dns issue

Why do you think that it is not a dns issue when

IPHostEntry iPHostEntry = Dns.GetHostEntry(host); // throws InvalidOperationException

Unfortunately the native Ethernet on my SC20260 is defective so that I could try your code only with an Enc28 module.
With the Enc28 module your code works flawlessly.
Did you try my suggestion to just use the command two times in a try/catch block.

  IPHostEntry iPHostEntry = null;
        try
        {
            iPHostEntry = Dns.GetHostEntry(host);    
        }
        catch { }

        try
        {
            iPHostEntry = Dns.GetHostEntry(host);    
        }
        catch { }

perhaps because I know it is not a dns problem, but exactly the problem i described

if it were dns problems, I would have written the text accordingly