---
title: "W5500-EVB-Pico multiple simultaneous TCP connections"
url: "https://maker.wiznet.io/forum/9458"
markdown_url: "https://maker.wiznet.io/forum/9458/md"
type: "Forum topic"
category: "MCU & Boards"
author: "novanovavita"
created: "2024-09-10T01:49:36+09:00"
last_activity: "2024-09-12T11:15:47+09:00"
language: "en"
tags: ["C/C++", "W5500"]
views: 8
replies: 1
source: "WIZnet Makers forum (https://maker.wiznet.io/forum/)"
---

# W5500-EVB-Pico multiple simultaneous TCP connections

## Question

Asked by novanovavita on 2024-09-10 in MCU & Boards.

I am creating two different TCP connections both to the W5500.

The first one succeeds but the second one fails: Connection Refused.

According to this documentation

<https://os.mbed.com/teams/WIZnet/code/Ethernet/docs/ee0f7508fb5c/group__WIZnet__socket__APIs.html#ga8cc0a2074b3aae98a132c1ae3c51188f>

I can just add multiple sockets to the same port. I would expect that the first connection will be handled by the first socket and the second one will be handled by the second one.

If I understood correctly modifying the example tcp loopback code like this

```plaintext
    /* Infinite loop */
    while (1) {
        for (int i = 0; i < 4; i++) {
            /* TCP server loopback test */
            if ((retval = loopback_tcps(SOCKET_LOOPBACK, g_loopback_buf, PORT_LOOPBACK)) < 0) {
                printf(" Loopback error : %d\n", retval);

                while (1)
                    ;
            }
        }

    }
```

should make the first 4 sockets handle TCP connections.

But as I said, it does not work.

Any ideas? How do I use multiple sockets for multiple TCP connections?

## Replies

### Reply 1 by TheoIm, 2024-09-12

Hello, here is the response.

It seems there is an error in your code. The first argument of `loopback_tcps`, which is the socket number, should be assigned as `i`. However, your code does not vary the socket number within the for loop. Please check your code.

---

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