CH395做TCP SERVER,斷開再連接,連接不上,求助

CH395做TCP SERVER,斷開再連接,連接不上,在TCP測試軟件端的本地端口+1后可以連接,如果本地端口不+1 仍用原端口則需要等待2分鐘,之后又可以連接了,即斷開后等2分鐘才可以重新連接。另外,只配置了socket0。相關(guān)代碼如下

unsigned char? CH395Init(void)

{

..............

CH395SetStartPara(FUN_PARA_FLAG_TCP_SERVER|SOCK_CTRL_FLAG_SOCKET_CLOSE); ? ? ? /*TCP SERVER支持多連接時,需初始化此啟動參數(shù)*/

..............

}

void Config_CH395_Work_Mode(void)
{
//? UINT8 i;
?/* socket 1為TCP Server模式,無需設(shè)置目的IP和源端口 */
? CH395SetSocketProtType(CH395_Socket_0,PROTO_TYPE_TCP);???????? /* 設(shè)置socket 1協(xié)議類型 */
? CH395SetSocketSourPort(CH395_Socket_0,8000);?????????????????? /* 設(shè)置socket 1源端口 */
? CH395OpenSocket(0);??????????????????????????????????????????? /* 打開socket 1 */
? CH395TCPListen (0);??????????????????????????????????????????? /* 開始監(jiān)聽 */?
}

void CH395SocketInterrupt(unsigned char sockindex)
{

..........

?if (sock_int_socket & SINT_STAT_DISCONNECT)????????????? /* 連接斷開,TCP模式下產(chǎn)生此中斷? */
? {
???
??? CH395CloseSocket(sockindex);
??? LED1_OFF();
??? CH395OpenSocket(sockindex);
??? CH395TCPListen (sockindex);
???
? }
? if (sock_int_socket & SINT_STAT_TIM_OUT)???????????????? /* ARP和TCP模式下會發(fā)生此中斷 */
? {
??? CH395CloseSocket(sockindex);
??? if (CH395_Work_Mode == TCP_CLIENT_MODE)
??? {
????? mDelaymS(50);
????? CH395OpenSocket(sockindex);
????? CH395TCPListen (sockindex);
????? CH395TCPConnect(sockindex);
??? }

................

}


已解決,結(jié)果時上位機的問題,用沁恒公司的測試軟件就行了


或者創(chuàng)建連接時選擇隨機端口


只有登錄才能回復(fù),可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频