Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Probelms In Sockets??


  • Please log in to reply
2 replies to this topic

#1 Nart Schinackow

Nart Schinackow

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts
  • LocationLondon

Posted 30 August 2012 - 02:18 PM

i have a problem with the netduino plus please read the code below ...

this code is the netduino code
INTERFACE = NetworkInterface.GetAllNetworkInterfaces()[0];
INTERFACE.EnableStaticIP("192.168.15.5", "255.255.255.0", "192.168.15.1");
END_POINT = new IPEndPoint(IPAddress.Parse("192.168.15.5"), 90);
Thread.Sleep(5000);
ledpin.Write(true);
SOCK = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
SOCK.Bind(END_POINT);
SOCK.Listen(1);
byte[] s=UTF8Encoding.UTF8.GetBytes("nart schinackow");
while (true)
{
ACCP_SOCK = SOCK.Accept();
for (byte i = 0; i < 10; i++)
ACCP_SOCK.Send(s);
ACCP_SOCK.Close();
}

this code is the pc code
private void button1_Click(object sender, EventArgs e)
{
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
sock.Connect(new IPEndPoint(IPAddress.Parse("192.168.15.5"), 90));
byte[] r = new byte[100];
for (int i = 0; i < 10; i++)
{
sock.Receive(r);
}
sock.Close();
}

each time i press the button on the windows application code it keeps giving me this exception on the netduino application:

#### 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.Socket::Send [IP: 0010] ####
#### TestNetduino.Program::ConfigureSockets [IP: 003d] ####
#### TestNetduino.Program::Main [IP: 0008] ####
#### SocketException ErrorCode = 10055
#### SocketException ErrorCode = 10055
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Microsoft.SPOT.Net.dll
#### SocketException ErrorCode = 10055
An unhandled exception of type 'System.Net.Sockets.SocketException' occurred in Microsoft.SPOT.Net.dll


thought trying same example between two windows application no problems happned why is that ?

#2 Nobby

Nobby

    Advanced Member

  • Members
  • PipPipPip
  • 70 posts

Posted 30 August 2012 - 10:28 PM

The first thing to change on the PC end is your calls to Socket.Recieve(). Since you aren't specifying how much data to read on each call, it will try to read enough data to fill the array and will block until it does unless

  • You close the socket
  • Have a ReadTimeout value set on the socket

Either way, an exception will be thrown on the PC application. Make the buffer smaller to match the length of the data or provide an amount to read. In your case, the PC application will try to read 1000 bytes all-up.

On the Netduino side of things, I never simply use Socket.Send(). I always tell it was data range to use from the array so that I know I have full control over safe execution. This doesn't mean that the Netduino exception is being caused by this.

#3 Nart Schinackow

Nart Schinackow

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts
  • LocationLondon

Posted 31 August 2012 - 12:14 PM

The first thing to change on the PC end is your calls to Socket.Recieve(). Since you aren't specifying how much data to read on each call, it will try to read enough data to fill the array and will block until it does unless

  • You close the socket
  • Have a ReadTimeout value set on the socket

Either way, an exception will be thrown on the PC application. Make the buffer smaller to match the length of the data or provide an amount to read. In your case, the PC application will try to read 1000 bytes all-up.

On the Netduino side of things, I never simply use Socket.Send(). I always tell it was data range to use from the array so that I know I have full control over safe execution. This doesn't mean that the Netduino exception is being caused by this.


Hello Nobby ,
Thanks for the reply i changed the netduino code to the following :
SOCK = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            SOCK.Bind(END_POINT);
            SOCK.Listen(1);
            byte[] s=UTF8Encoding.UTF8.GetBytes("nart schinackow");
            while (true)
            {
                ACCP_SOCK = SOCK.Accept();
                for (byte i = 0; i < 10; i++)
                    ACCP_SOCK.Send(s, i, 1, SocketFlags.None);
                ACCP_SOCK.Close();
            }
and pc code to the following

 Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            sock.Connect(new IPEndPoint(IPAddress.Parse("192.168.15.5"), 90));
            byte[] r = new byte[1];
            for (int i = 0; i < 10; i++)
            {
                sock.Receive(r, 0, 1, SocketFlags.None);
            }
            sock.Close();


still the exception appears!!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.