---
title: "ioLibrary recv only returns Zeros"
url: "https://maker.wiznet.io/forum/13050"
markdown_url: "https://maker.wiznet.io/forum/13050/md"
type: "Forum topic"
category: "Ethernet Chips"
author: "mdxg"
created: "2018-09-10T08:16:44+09:00"
last_activity: "2018-09-10T13:38:47+09:00"
language: "en"
views: 1428
replies: 8
source: "WIZnet Makers forum (https://maker.wiznet.io/forum/)"
---

# ioLibrary recv only returns Zeros

## Question

Asked by mdxg on 2018-09-10 in Ethernet Chips.

Hello Wiznet Community,

I want to use a w5500 connected via spi in a project to realize a Ethernet interface.
For this I created a small board and ported the ioLibrary for my setup.
The port works well except of the recv function. I can open a socket, start listening and
establish a connection. If I send data via the TCP connection recv returns the number of bytes correctly
but fills the buffer with only zeros.

This is a short code example. All functions (socket, listen) do return SOCK_OK.

wiz_NetInfo netInfo = { .mac = { 0x00, 0x08, 0xdc, 0xab, 0xcd, 0xef },
.ip = { 192, 168, 1, 222 },
.sn = { 255, 255, 255, 0 },
.gw = { 192, 168, 1, 1 },
.dns = { 0, 0, 0, 0 },
.dhcp = NETINFO_STATIC };

int main(){
//Board specific init code
wizchip_setnetinfo( &netInfo );
socket( 0, Sn_MR_TCP, 22000, 0 );
listen(0);
while( getSn_SR(0) != 0x17 ); //Wait for connection

```
uint8_t buffer[128];
while(1){
    tmp = recv(0, buffer, 12 );
    buffer[tmp] = 0;
    printf( "%s\n", buffer );
}

return 0;
```

}
If you send for example “Hello” then tmp is 6 which is correct.
For printf with %s there is no output. If I print every byte as int you can see that every byte is 0.

Does anybody have an idea where this bug could come from?

## Replies

### Reply 1 by Eugeny, 2018-09-10

![](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/48.png) mdxg:

> If you send for example “Hello” then tmp is 6 which is correct.

Data “Hello” is having 5 bytes it in?

![](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/48.png) mdxg:

> For printf with %s there is no output

%s outputs till null char. If first char appears to be null nothing is displayed. I propose you making a data dump in hex.

### Reply 2 by mdxg, 2018-09-10

Sorry the value of tmp for “Hello” is 7 and the hex value of the buffer after a read out
is [0,0,0,0,0,0,0]

### Reply 3 by Eugeny, 2018-09-10 (in reply to reply 2)

![](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/48.png) mdxg:

> Sorry the value of tmp for “Hello” is 7

??? ![:rofl:](https://emoji.discourse-cdn.com/twitter/rofl.png?v=12) I think you can count letters - H E L L O is 5 letters, thus size returned must be 5, not 6 and not 7. Use wireshark to see what is actually going on the network. Send another phrase “Hello Friends” to see how many bytes recv will return.

### Reply 4 by mdxg, 2018-09-10

No thats okay. If you use putty as ascii to tcp terminal, putty adds two characters for newline at the end of the payload.

### Reply 5 by Eugeny, 2018-09-10 (in reply to reply 4)

Try declaring `uint8_t buffer[128];` outside of the `main()` function (in the `netInfo` declaration location).

### Reply 6 by mdxg, 2018-09-10

Okay I did declare the buffer outside of the main. Still only zeros in the return

### Reply 7 by Eugeny, 2018-09-10 (in reply to reply 6)

I think there’s some issue with pointers. Before performing recv(), initialize `buffer` with some values, for example 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 to see if it will have these values after recv() execution or recv will really reload the array with zeros.

### Reply 8 by mdxg, 2018-09-10

Okay I did work on the buffer stuff and found the error. The printing of the buffer was the original error.
The connection now works but from time to time the receive method receives way more bits than I sent.

Thanks alot for the help:)

---

Source: https://maker.wiznet.io/forum/13050
