C++ Socket port is occupied solution

windows:

BOOL bReuseaddr=TRUE;
setsockopt (s,SOL_SOCKET ,SO_REUSEADDR,(const char*)&bReuseaddr,sizeof(BOOL));

Linux

int opt = 1;
setsockopt(LisSockfd,SOL_SOCKET,SO_REUSEADDR,&opt,sizeof( opt ));

Setting the socket property to SO_REUSEADDR (allowing the socket to bind with an address already in use) fixes the bind failure!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325444723&siteId=291194637