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

Tested the project as is and could not see any problems. Anything else we can try?

IP: 0.0.0.0
Subnet: 0.0.0.0
Gateway: 0.0.0.0
DNS 1: 0.0.0.0
IP: 192.168.86.40
Subnet: 255.255.255.0
Gateway: 192.168.86.1
DNS 1: 192.168.86.1
Network is ready to use
12:00:14.071
Connection established
12:00:14.207

try it over few days and multiple times especially if the remote server has high load or close it and also Ftp doesn't work with the host ftp://speedtest.tele2.net/ · Issue #718 · ghi-electronics/TinyCLR-Libraries · GitHub
i was able to reproduce it easy multiple times few weeks ago but not on LAN
sometimes a problem replication must take place in near time

Then we should close till we have a way of replicating the issue. Thank for helping.

1 Like