CH395做TCP SERVER,断开再连接,连接不上,在TCP测试软件端的本地端口+1后可以连接,如果本地端口不+1 仍用原端口则需要等待2分钟,之后又可以连接了,即断开后等2分钟才可以重新连接。另外,只配置了socket0。相关代码如下
unsigned char CH395Init(void)
{
..............
CH395SetStartPara(FUN_PARA_FLAG_TCP_SERVER|SOCK_CTRL_FLAG_SOCKET_CLOSE); /*TCP SERVER支持多连接时,需初始化此启动参数*/
..............
}
void Config_CH395_Work_Mode(void)
{
// UINT8 i;
/* socket 1为TCP Server模式,无需设置目的IP和源端口 */
CH395SetSocketProtType(CH395_Socket_0,PROTO_TYPE_TCP); /* 设置socket 1协议类型 */
CH395SetSocketSourPort(CH395_Socket_0,8000); /* 设置socket 1源端口 */
CH395OpenSocket(0); /* 打开socket 1 */
CH395TCPListen (0); /* 开始监听 */
}
void CH395SocketInterrupt(unsigned char sockindex)
{
..........
if (sock_int_socket & SINT_STAT_DISCONNECT) /* 连接断开,TCP模式下产生此中断 */
{
CH395CloseSocket(sockindex);
LED1_OFF();
CH395OpenSocket(sockindex);
CH395TCPListen (sockindex);
}
if (sock_int_socket & SINT_STAT_TIM_OUT) /* ARP和TCP模式下会发生此中断 */
{
CH395CloseSocket(sockindex);
if (CH395_Work_Mode == TCP_CLIENT_MODE)
{
mDelaymS(50);
CH395OpenSocket(sockindex);
CH395TCPListen (sockindex);
CH395TCPConnect(sockindex);
}
................
}