---
title: "Unknown status when TCP client runs."
url: "https://maker.wiznet.io/forum/13475"
markdown_url: "https://maker.wiznet.io/forum/13475/md"
type: "Forum topic"
category: "Ethernet Chips"
author: "joyn7"
created: "2019-09-09T09:32:27+09:00"
last_activity: "2019-09-10T02:23:18+09:00"
language: "en"
views: 620
replies: 2
source: "WIZnet Makers forum (https://maker.wiznet.io/forum/)"
---

# Unknown status when TCP client runs.

## Question

Asked by joyn7 on 2019-09-09 in Ethernet Chips.

The client runs.
int32_t WIZNET_Run(uint8_t sn, uint8_t* buf, uint8_t* destip, uint16_t destport, uint16_t *rcv_size)
{
int32_t loc_ret, ret = 0; // return value for SOCK_ERRORs
uint16_t size = 0, sentsize=0;
static int first_send = 0;

```
     // Port number for TCP client (will be increased)
    static uint16_t any_port = 	50000;

    uint8_t status = wiz_getSn_SR(sn);

   switch(status)
   {
        case SOCK_ESTABLISHED :
            if(status & Sn_IR_CON)	
            {
	    wiz_setSn_IR(sn, Sn_IR_CON);  

	    if((size = getSn_RX_RSR(sn)) > 0) 
               {
		if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE; /
		loc_ret = wiz_recv(sn, buf, size); 
		if(loc_ret <= 0) 
		    	 return STAT_RX_FAILED; 
		 size = (uint16_t) loc_ret;
		    
		*rcv_size = size;
         }
	    
	 ret = STAT_SOCK_OK;
     break;

     case SOCK_CLOSE_WAIT :
         loc_ret = wiz_disconnect(sn);
         if(loc_ret != SOCK_OK) 
        
         ret = STAT_SOCK_NOT_OK;
     break;

     case SOCK_INIT :
         loc_ret = wiz_connect(sn, destip, destport);
	     if( loc_ret != SOCK_OK) 
	    	 ret = STAT_SOCK_NOT_OK;
     break;

     case SOCK_CLOSED:
         wiz_close(sn);
    	 
         ret = wiz_socket(sn, Sn_MR_TCP, any_port++, 0x00);
	     if(ret != sn)
	     {
             if(any_port == 0xffff) 
            	 any_port = 50000;
             
             ret = STAT_SOCK_NOT_OK; // TCP socket open with 'any_port' port number
         } 
	     
        //set auto keep alive every 5 sec
        setSn_KPALVTR(sn, 1); 
     break;
     
     default:
     break;
```

}
return ret;
}

I get SOCK_ESTABLISHED and it runs OK.
wiznet_status = WIZNET_Run(SOCK_TCPS, read_buf, tcp_server_ip, PORT_TCPS, &TCP_RecSize);

But if I send something
if (wiznet_status == STAT_SOCK_OK)
{
if (wiz_send(SOCK_TCPS, messages_Q_Buffer, Q_RecvSize) == ERROR)
{
printf(“Error Sending Message\n”);
}

I get in uint8_t status = wiz_getSn_SR(sn); - status = 0x03 and it is invalid status – there are no such documented status.

## Replies

### Reply 1 by Eugeny, 2019-09-09

![](https://avatars.discourse-cdn.com/v4/letter/j/b77776/48.png) joyn7:

> But if I send something

Most probably you supply some wrong argument to the sending routine, or there’s some memory overlap and application writes to the unintended locations (in wrong registers).

It is hard to suggest anything as there’s no tech data available on the issue, but I hope you have got a direction to research into.

### Reply 2 by joyn7, 2019-09-09 (in reply to reply 1)

But why status gets an invalid value - 0x03? It stays this way till I reset.

---

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