WIZnet Developer Forum

W5200, UDP sendto localhost

Dear wiznet,

I use W5200 to implement the ONC/RPC for achieving a VXI based Network Instrument procotol.
While I am implementing RPC, I need to send a packet to a localhost UDP socket port 111.
but the return value of sendto() is always 0x08(timeout), could you please help me to figure out this problem?
the procedures would be like the following :

if(socket(s,Sn_MR_UDP,111,0x00) == 0)    /* reinitialize the socket */
{
	printf("\r\n%d : Fail to create socket.",s);
}                                			                
Delay_ms(100);
printf("status = 0x%02x\r\n",getSn_SR(s));

Delay_ms(100);
printf("status = 0x%02x\r\n",getSn_SR(s));

if(getSn_SR(s) == 0x22){
	ipaddr = 0x0100007F;
	status = sendto(s,"*IDN?",5,(uint8*)&ipaddr,111);
	printf("status = 0x%02x\r\n",status);
}

Hi~calvin2001

After socket open operate, please read the Sn_Port register.
You have to set the port number as HEX value when Socket port write in Sn_Port register.

thanks,
EK

Hello EK,

thanks for your reply,I added the Sn_PORT0 polling function after socket open operation, but still get the same result, I also tried sending packet to an external listened UDP server other than sending to a localhost 127.0.0.1, it works, so I wonder if W5200 can send packet appropriately to itself, my socket function is as following:
that would be great if you can try a localhost sending procedure and show me the example, thanks a lot.

uint8 socket(SOCKET s, uint8 protocol, uint16 port, uint8 flag)
{
uint8 ret, src_port=0;
if ((protocol == Sn_MR_TCP) || (protocol == Sn_MR_UDP) || (protocol == Sn_MR_IPRAW) || (protocol == Sn_MR_MACRAW) || (protocol == Sn_MR_PPPOE))
{
close(s);
IINCHIP_WRITE(Sn_MR(s),protocol | flag);
if (port != 0) {
IINCHIP_WRITE(Sn_PORT0(s),(uint8)((port & 0xff00) >> 8));
IINCHIP_WRITE((Sn_PORT0(s) + 1),(uint8)(port & 0x00ff));
} else {
local_port++; // if don’t set the source port, set local_port number.
IINCHIP_WRITE(Sn_PORT0(s),(uint8)((local_port & 0xff00) >> 8));
IINCHIP_WRITE((Sn_PORT0(s) + 1),(uint8)(local_port & 0x00ff));
}
IINCHIP_WRITE(Sn_CR(s),Sn_CR_OPEN); // run sockinit Sn_CR

	while(src_port != port){
		src_port = IINCHIP_READ(Sn_PORT0(s)) <<8;
		src_port = src_port + IINCHIP_READ((Sn_PORT0(s) + 1));
	}
	printf("src_port = %d\r\n",src_port);
	

	/* wait to process the command... */
	while( IINCHIP_READ(Sn_CR(s)) ) 
		;
	/* ------- */
	ret = 1;
}
else
{
	ret = 0;
}
return ret;

}

Hello,

How is this case going?? I am still struggling with this issue…
can you simply make a try whether W5200 support connecting to itself(127.0.0.1) or not,
if it couldn’t, I could find other way to satisfy my application.

hi,

Sorry, our server occur the problem and I don’t receive your comment.

On most computer systems, “localhost” resolves to the IP address 127.0.0.1, which is the most commonly used IPv4 loopback address.
127.0.0.1 mean internal loopback of PC and PC don’t send output data.
Therefore, IP of PC(127.0.0.1) isn’t use as communica

thanks,
Ekkim :slight_smile:

Hi ekkim,

thanks for your reply,

Yes I understand that the localhost transmission is a typical loopback purpose in most platforms,
but my application of localhost transmission was built for W5200 only,
I open a TCP/UDP socket server on W5200, for my specific purpose, I need to open one another client socket on W5200,the client socket should send one request packet to the listened socket to get some mapping data, but I failed, because the local client socket couldn’t send data to the local server, all transmission was made by W5200.

If my explanation is still not clear, please let me know.

Calvin

Hi~

Are you use both Server ip and Client ip as 127.0.0.1?
If you connect Server(W5200) and Client(W5200) without switch hub via lan,you can send the data.
but If you connect Server and Client via switch hub, you can’t send the data.
because the ip collision occur when switch hub use.

thanks,
EK

Are you use both Server ip and Client ip as 127.0.0.1?
If you connect Server(W5200) and Client(W5200) without switch hub via lan,you can send the data.
but If you connect Server and Client via switch hub, you can’t send the data.
because the ip collision occur when switch hub use.

Hi EK,

About the connection of my test, the Client(W5200) and the Server(W5200) are all built in one chip, there is no any physical ethernet cable connection exist, so that it doesn’t connect to any hub, the procedures are as following:(TCP protocol)

  1. open a socket on W5200 socket 0, port 111.
  2. listen socket 0.
  3. open a socket on W5200 socket 1, bind port 111.
  4. connect socket 1 to 127.0.0.1
  5. send data by socket 1
    Theoretically, these two socket should be able to transmit/receive, but they don’t. I don’t know where the problem is.

Copyright © 2017 WIZnet Co., Ltd. All Rights Reserved.