WIZnet Developer Forum

wiznet 5500 connect() SOCK_BUSY problem . Why ??

uint8_t s = 0 ;//socket numarası
uint8_t server_ip[4] = {192,168,2,192} ; // Oluşturulan server’ın ip’si gösterilir
uint8_t Baglan ; //Connect fonkişyonundan dönen değeri tutmak için kullanacağız .
uint16_t port_num = 5656 ;

socket(0 , Sn_MR_TCP, port_num , 0) ; // SocketNumber,Protocol,Port,Flag
//Sn_MR_TCP—> This configures the protocol mode of Socket
//5656 —> Oluşturulan serverdaki port numarası
//Flag default olarak kullanılıyor .Sebebini öğren ??

while (Baglan != SOCK_OK) // Return “SOCK_OK” olana kadar bağlanmaya dener cihaz servera
{
Baglan = connect(s, server_ip, port_num); // SocketNumber,ServerIp,Port
//Server_ip —> Oluşturduğumuz serverdaki ip adresi
//Port —> Oluşturduğumuz serverdaki port numarası
}

Baglan = 0 ; // Bağlantı kurulduktan sonra birdahaki işlem için “Baglan” degeri resetlenir .

im using this code . But connect()'s return value is SOCK_BUSY . its not SOCK_OK . Why is the happening .

Please check the return value of socket().
This error does not occur if the socket is opened normally.

Thank you for answer

i checked socket . İts returned socket num . its working normally . now connect’s return value is -3 in decimal form . its mean is SOCKERR_SOCKINIT . its mean is " Socket is not initialized or SIPR is Zero IP address when Sn_MR_TCP . " what does is mean ? im usign stm32f303-re . İm tring tcp client with w5500 . İ cant find enough resources . I’ll be happy if you can help me .

im using this code :

void cs_sel() {
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_RESET); //CS LOW
}

void cs_desel() {
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET); //CS HIGH
}

uint8_t spi_rb(void) {
uint8_t rbuf;
HAL_SPI_Receive(&hspi3, &rbuf, 1, 0xFFFFFFFF);
return rbuf;
}

void spi_wb(uint8_t b) {
HAL_SPI_Transmit(&hspi3, &b, 1, 0xFFFFFFFF);
}
/* ----------------------------------------------*/

uint8_t bufSize = {2, 2, 2, 2};

/* ----------------------------------------------*/

reg_wizchip_cs_cbfunc(cs_sel, cs_desel);
reg_wizchip_spi_cbfunc(spi_rb, spi_wb);

/* ----------------------------------------------*/

wizchip_init(bufSize, bufSize);
wiz_NetInfo netInfo = { .mac = {0x00, 0x08, 0xdc, 0xab, 0xcd, 0xef}, // Mac address
.ip = {192, 168, 2, 2}, // IP address
.sn = {255, 255, 255, 0}, // Subnet mask
.gw = {192, 168, 2, 1}}; // Gateway address
wizchip_setnetinfo(&netInfo);
uint8_t s ;
s = 1 ;
uint8_t server_ip[4] = {192,168,2,1} ;
uint8_t Baglan ;
int32_t ret=2 ; // check socket value

/* ----------------------------------------------*/
ret = socket(s,Sn_MR_TCP,5656,SF_TCP_NODELAY);

  while(Baglan != SOCK_OK)
  {
	  Baglan = connect(s,server_ip,3000);

  }
  Baglan = 0 ;

}

The w5500 has 8 sockets.

Change this to uint8_t bufSize={2,2,2,2,2,2,2,2};

Thank you for answer but i tried but not working again . ithink problem is not in socket . Because i updated code and work correctly. this section .

if (Sn_SR(0) != SOCK_INIT) // The socket initialization query completes.
{
ret = socket(s,Sn_MR_TCP,5656,SF_TCP_NODELAY);
}

im using stm32cubeide . İ found problem in connect() fuction .
uint8_t s ;
s = 0 ;
uint8_t server_ip[4] = {192,168,1,5} ; // This should be in my pc .
uint8_t Baglan ;
do
{
Baglan = connect(s,server_ip,5656);

  }while(Baglan != SOCK_OK);
  Baglan = 0 ;

code stays inside the while loop and Baglan cant SOCK_OK . I couldn’t find the reason for this .

and after i tried differntly connection like this :

       setSn_DIPR(s, server_ip); //set server_ip
   HAL_Delay(500);
   setSn_DPORT(s, 5656) //set port number
   HAL_Delay(500);
   setSn_CR(s,Sn_CR_CONNECT); //set sn_sr_connect
   HAL_Delay(1000);

and i tried connect to hercule’s tcp server . but its not worked .

At another point, I started to think I was making a mistake.

im using hercules and wireshark . this is the screenshots I see when I run the code .

İ used first time this apps . I think the connect function works according to the application. But I can not understand why I could not establish a connection with the server in the other application.

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