---
title: "TCP Client not connecting"
url: "https://maker.wiznet.io/forum/14141"
markdown_url: "https://maker.wiznet.io/forum/14141/md"
type: "Forum topic"
category: "Ethernet Chips"
author: "mateusz"
created: "2021-02-04T13:44:20+09:00"
last_activity: "2021-02-11T16:27:38+09:00"
language: "en"
views: 608
replies: 3
source: "WIZnet Makers forum (https://maker.wiznet.io/forum/)"
---

# TCP Client not connecting

## Question

Asked by mateusz on 2021-02-04 in Ethernet Chips.

Hi, I am working on a device with the W6100 chip and having some issues with connecting to a TCP Client.
I have followed the documenation directly <https://wizwiki.net/wiki/lib/exe/fetch.php/products:w6100:w6100_ds_v104e.pdf>
and nothing was happening, then I found some examples for W5500 that showed that you have to run OPEN command after setting the destination address and port.
Then something start working, I got some messages in wireshark:
![image](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/2/28dc7f9b3d5b6e56284a534c86a417efbcfec64f.png)
But it still doesn’t stay connected, on the server side I am using just plain nc and it throws an error:

```
Listening on 0.0.0.0 5000
nc: accept: Software caused connection abort
```

I am missing something after doing connect?

```
       struct eth_socket_mode mode = {
            .multi = 0,
            .broadcast = 0,
            .noackdelay = 0,
            .unicast = 0,
            .protocol = ETH_SOCKET_MODE_PROTOCOL_TCP4,
        };
        
        ETH_WRITE_SOCKET_CONF(priv->dev, priv->number, ETH_SOCKET_MODE, &mode, sizeof(mode));
        ETH_WRITE_SOCKET_CONF(priv->dev, priv->number, ETH_SOCKET_DEST4, &parsed_ip, sizeof(parsed_ip));
        ETH_WRITE_SOCKET_CONF(priv->dev, priv->number, ETH_SOCKET_PORT, &parsed_port, sizeof(parsed_port));
        uint8_t command = ETH_SOCKET_COMMAND_OPEN;
        ETH_WRITE_SOCKET_CONF(priv->dev, priv->number, ETH_SOCKET_COMMAND, &command, sizeof(command));

        uint64_t start = tools_get_current_ms();
        do {
            msleep(5);
            ETH_READ_SOCKET_CONF(priv->dev, priv->number, ETH_SOCKET_COMMAND, &command, sizeof(command));
            _info("command: %d\n", command);
        } while (command != 0 && tools_get_current_ms() - start < priv->timeout);

        command = ETH_SOCKET_COMMAND_CONNECT;
        ETH_WRITE_SOCKET_CONF(priv->dev, priv->number, ETH_SOCKET_COMMAND, &command, sizeof(command));

        start = tools_get_current_ms();
        do {
            msleep(5);
            ETH_READ_SOCKET_CONF(priv->dev, priv->number, ETH_SOCKET_COMMAND, &command, sizeof(command));
            _info("command: %d\n", command);
        } while (command != 0 && tools_get_current_ms() - start < priv->timeout);
```

Here is my code for opening TCP Connection. Any one can help me with that?

## Replies

### Reply 1 by becky, 2021-02-09

I don’t understand your environment well.
Is the w6100 a TCP server?
First of all, TCP Client’s port is 0 when viewed through wireshark.
This seems to be a problem.

### Reply 2 by mateusz, 2021-02-09 (in reply to reply 1)

I know that my code contains a lot of abstraction. Sorry about that.
W6100 is a client in this situation and is connecting to a TCP Server on my PC.
If that helps I can get some SPI capture so you can better see what is writing to W6100.

### Reply 3 by mateusz, 2021-02-11

Ok I found it out! Thanks for the suggestion that the port is 0.
I tried to set 0x0114 to 14001 and now it opens.
Sadly that isn’t mention in the documentation but important that it works now :).

---

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