---
title: "W6100 socket connection is not establishing."
url: "https://maker.wiznet.io/forum/9438"
markdown_url: "https://maker.wiznet.io/forum/9438/md"
type: "Forum topic"
category: "Ethernet Chips"
author: "ravikant"
created: "2024-08-06T22:03:42+09:00"
last_activity: "2024-09-10T20:14:33+09:00"
language: "en"
views: 6
replies: 0
source: "WIZnet Makers forum (https://maker.wiznet.io/forum/)"
---

# W6100 socket connection is not establishing.

## Question

Asked by ravikant on 2024-08-06 in Ethernet Chips.

Hi,

I am working with PSOC6 and W610io Ethernet controller. I write TCP-Echo server. the socket is initialized and starts to listen, but the socket is not established. SPI protocol gives a chip version Register. Are there any problems in the code? I write the same code for STM32F746 it works but with PSOC6 it does not work.

#define LISTEN_PORT 5000
#define RECEIVE_BUFF_SIZE 1024
uint8_t receive_buff[RECEIVE_BUFF_SIZE];

wizchip_setnetinfo(&gWIZNETINFO);
printf("VERSION(%x) = %.2x \r\n", _VER_, getVER());
print_network_information();

wiz_PhyConf phyconf;

phyconf.duplex=PHY_DUPLEX_FULL;
phyconf.speed=PHY_SPEED_100;//100MBps Ethernet link speed
phyconf.mode=PHY_MODE_AUTONEGO;//best to go with auto-negotiation

ctlwizchip(CW_SET_PHYCONF, (void*) &phyconf);//PHY Configuration Command*/
//*** End Phy Configuration
printf("\r\n*SIMPLE TCP ECHO SERVER**\r\n");
PrintPHYConf();

while(1)
{

printf("\r\nInitializing server socket\r\n");

if(socket(1,Sn_MR_TCP4,LISTEN_PORT,0)!=1)
{
printf("Cannot create Socket!\r\n");
while(1);//halt here
}

uint8_t socket_io_mode=SOCK_IO_BLOCK;

ctlsocket(1, CS_SET_IOMODE , &socket_io_mode);//set blocking IO mode
uint8_t lis = listen(1);
printf("Start listening on port %d ! \r\n",lis);
//Make it a passive socket (i.e. listen for connection)
if(lis!=SOCK_OK)//our socket id is 1 (w5500 have 8 sockets from 0-7)
{
printf("Cannot listen on port %d",LISTEN_PORT);
while(1);
}
uint8_t sr=0x00;//socket status register
do{
Cy_SysLib_Delay(100);
sr=getSn_SR(1);
printf("Start listening on port %x ! \r\n",sr);
}while (sr!= SOCK_ESTABLISHED);

if(sr==0x00)
{
printf("Some error occurred on server socket. Please restart.\r\n");
while(1);
}
if(sr==0x17)
{
printf("A client connected!\r\n");
printf("Waiting for Client Data ...!\r\n");

while(1)
{
int len=recv(1, receive_buff, RECEIVE_BUFF_SIZE);
if(len==SOCKERR_SOCKSTATUS)
{
//client has disconnected
printf("Client has disconnected\r\n");
printf("*** SESSION OVER ***\r\n\r\n");
// break;
}
receive_buff[len]=''\0'';
printf("Received %d bytes from client\r\n",len);
printf("Data Received: %s", receive_buff);
//Echo the data back encloused in a [] pair
send(1,(uint8_t*)"[",1);//starting sq bracket
send(1,receive_buff,len);// the data
send(1,(uint8_t*)"]",1);//closing sq bracket
printf("\r\nECHO sent back to client\r\n");
//Look for quit message and quit if received
if(strcmp((char*)receive_buff,"QUIT")==0)
{
printf("Received QUIT command from client\r\n");
printf("Disconnecting ... \r\n");
printf("*** SESSION OVER ***\r\n\r\n");
disconnect(1);//disconnect from the clinet
break;//come out of while loop
}
}
}//if block, client connect success
}//while loop
}

---

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