SocketException ErrorCode = 10054

Iā€™m running the following using SDK 4.3:


public void TransmitValue(string json)
        {
            using (var request = HttpWebRequest.Create(_postUri))
            {
                request.Method        = "POST";
                request.ContentType   = "application/json";
                request.ContentLength = json.Length;                

                using (var streamWriter = new StreamWriter(request.GetRequestStream()))
                {
                    streamWriter.Write(json);
                    streamWriter.Flush();
                }
            }
        }

The line containing ā€œrequest.GetRequestStream()ā€ is the one that explodes into this:


    #### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (1) ####
    #### Message: 
    #### Microsoft.SPOT.Net.SocketNative::send [IP: 0000] ####
    #### System.Net.Sockets.Socket::Send [IP: 0018] ####
    #### System.Net.Sockets.NetworkStream::Write [IP: 0051] ####
    #### System.Net.InputNetworkStreamWrapper::Write [IP: 000a] ####
    #### System.Net.HttpWebRequest::SubmitRequest [IP: 007d] ####
    #### System.Net.HttpWebRequest::GetRequestStream [IP: 0008] ####
    #### CareForPlant.Program::OnTimerTick [IP: 0046] ####
    #### Gadgeteer.Timer::dt_Tick [IP: 0018] ####
    #### Microsoft.SPOT.DispatcherTimer::FireTick [IP: 0010] ####
    #### Microsoft.SPOT.Dispatcher::PushFrameImpl [IP: 0054] ####
    #### Microsoft.SPOT.Dispatcher::PushFrame [IP: 001a] ####
    #### Microsoft.SPOT.Dispatcher::Run [IP: 0006] ####
    #### Gadgeteer.Program::Run [IP: 001d] ####
    #### SocketException ErrorCode = 10054
    #### SocketException ErrorCode = 10054
    #### SocketException ErrorCode = 10054
    #### SocketException ErrorCode = 10054
    #### SocketException ErrorCode = 10054
Exception thrown: 'System.Net.Sockets.SocketException' in System.Http.dll
    #### SocketException ErrorCode = 10054
An exception of type 'System.Net.Sockets.SocketException' occurred in System.Http.dll but was not handled in user code
    #### SocketException ErrorCode = 10054
Exception performing Timer operation
The program '[5] Micro Framework application: Managed' has exited with code 0 (0x0).

I found a similar post but saw no solution to it. I have initialized the network beforehand using this:


        public void InitializeNetwork()
        {
            _display.Clear();
            _display.Print("Connecting...");

            _network = new EthernetENC28(4);            

            _network.NetworkInterface.Open();
            _network.NetworkInterface.EnableDhcp();
            _network.NetworkInterface.EnableDynamicDns();

            Thread.Sleep(250);

            if (!_network.NetworkInterface.CableConnected)
            {
                _display.Print("No cable!", 1);            
            }

            while (_network.NetworkInterface.IPAddress == "0.0.0.0")
            {
                Thread.Sleep(250);
            }           
            _display.Print("Net: " + _network.NetworkInterface.IPAddress, 1);
            Thread.Sleep(2000);
        }

I need ideas for what I may be doing wrong

I have also seen this because the request was bad formed. Containing illegal header configuration or a bad request.

@ njbuch - Do you have an example of a well formed request?

@ digitaldias -


POST /pass.php HTTP/1.1

Host: 127.0.0.1
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
DNT: 1
Referer: http://127.0.0.1/pass.php
Cookie: passx=87e8af376bc9d9bfec2c7c0193e6af70; PHPSESSID=l9hk7mfh0ppqecg8gialak6gt5
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 30
username=zurfyx&pass=password

1 Like