InterviewSolution
| 1. |
Is There Any Way To Tell If A Socket Is Already Connected? |
|
Answer» There are two ways to DETERMINE if a socket is connected. The easiest is to check the return value of ISOCKET_Connect(). When a socket is ALREADY connected, ISOCKET_Connect() will return EISCONN. It is also possible to monitor the state of a socket connection by registering for the socket status change events NE_SO_CLOSING, and NE_SO_CLOSED with INETMGR_OnEvent(). Using this method, your application can avoid trying to connect an already connected socket. For more information about network and socket events, including NE_SO_CLOSING and NE_SO_CLOSED, please refer to the following include file: AEENet.h For Example: // Register to receive Network and Socket events There are two ways to determine if a socket is connected. The easiest is to check the return value of ISOCKET_Connect(). When a socket is already connected, ISOCKET_Connect() will return EISCONN. It is also possible to monitor the state of a socket connection by registering for the socket status change events NE_SO_CLOSING, and NE_SO_CLOSED with INETMGR_OnEvent(). Using this method, your application can avoid trying to connect an already connected socket. For more information about network and socket events, including NE_SO_CLOSING and NE_SO_CLOSED, please refer to the following include file: AEENet.h For Example: // Register to receive Network and Socket events |
|