Mars跟服务器建立链接之后断开

vc9ivgsu  于 5个月前  发布在  其他
关注(0)|答案(3)|浏览(59)

1: 能正常建立链接🔗,日志显示socket connected,并且回调并打印了 <- OnLongLinkEstablished
2: 建立链接后自动发送的一个noop(cmdid=6)的检测包到服务器,服务器有收到,并返回给我
3:日志有收到并回调打印日志end noop
4: 接下来就显示 [socketbreaker.cc, Clear, 129]: Ret=-1
5: 然后打印了[longlink.cc, __RunReadWrite, 570]:task socket close sock:69, remote disconnect, net_type:task socket close getsocktcpinfo:tcpi_state=0x8,.....的日志

请问这种流程下,是什么情况导致的呢

izj3ouym

izj3ouym1#

你好请问解决了吗。我这边也是连接上之后自动发送一个心跳,服务器也回复了一个一样的心跳。
然后我发送一个消息给服务器,服务器也收到了,但是服务器马上返推一个消息的时候,本地socket关闭了。
多次测试应该就是反推消息的时候,socket被关闭。不知道流程什么情况?

4ngedf3f

4ngedf3f2#

我这边也是会断开。
目前情况是,连接服务器后,服务器返回一个心跳包,客户端就正常不会断开。
但是客户端发送信息给服务端后,服务端收到消息,返回任意内容,就断开了。
@garryyan 大佬能帮忙看下什么原因吗?

下面是我测试的数据,cmdid我改成24(十六进制是18)了。
仔细看13:30:44和13:30:57,在客户端发了两条非心跳包消息后,连接就断开了。

客户端:127.0.0.1 时间:2020/2/29 13:30:38 已经TCP连接!
(TCP)来自:127.0.0.1:50921 收到:20(Bytes) 时间:2020/2/29 13:30:38 
数据:00 00 00 14 00 00 00 C8 00 00 00 18 FF FF FF FF 00 00 00 00 
服务器自动回复:127.0.0.1 
数据:00 00 00 14 00 00 00 C8 00 00 00 18 FF FF FF FF 00 00 00 00

(TCP)来自:127.0.0.1:50921 收到:54(Bytes) 时间:2020/2/29 13:30:44 
数据:00 00 00 14 00 00 00 C8 00 00 00 03 00 00 00 02 00 00 00 22 0A 0A 74 65 73 74 5F 74 6F 6B 65 6E 12 01 31 1A 03 61 6C 6C 22 01 31 2A 09 E5 93 88 E5 93 88 E5 93 88 
服务器自动回复:127.0.0.1 
数据:00 00 00 14 00 00 00 C8 00 00 00 18 FF FF FF FF 00 00 00 00

客户端:127.0.0.1 时间:2020/2/29 13:30:56 已断开TCP连接!
客户端:127.0.0.1 时间:2020/2/29 13:30:57 已经TCP连接!

(TCP)来自:127.0.0.1:50929 收到:20(Bytes) 时间:2020/2/29 13:30:57 
数据:00 00 00 14 00 00 00 C8 00 00 00 18 FF FF FF FF 00 00 00 00 
服务器自动回复:127.0.0.1 
数据:00 00 00 14 00 00 00 C8 00 00 00 18 FF FF FF FF 00 00 00 00

(TCP)来自:127.0.0.1:50929 收到:54(Bytes) 时间:2020/2/29 13:30:57 
数据:00 00 00 14 00 00 00 C8 00 00 00 03 00 00 00 02 00 00 00 22 0A 0A 74 65 73 74 5F 74 6F 6B 65 6E 12 01 31 1A 03 61 6C 6C 22 01 31 2A 09 E5 93 88 E5 93 88 E5 93 88 
服务器自动回复:127.0.0.1 
数据:00 00 00 14 00 00 00 C8 00 00 00 18 FF FF FF FF 00 00 00 00

客户端:127.0.0.1 时间:2020/2/29 13:31:09 已断开TCP连接!
客户端:127.0.0.1 时间:2020/2/29 13:31:12 已经TCP连接!

(TCP)来自:127.0.0.1:50935 收到:20(Bytes) 时间:2020/2/29 13:31:12 
数据:00 00 00 14 00 00 00 C8 00 00 00 18 FF FF FF FF 00 00 00 00 
服务器自动回复:127.0.0.1 
数据:00 00 00 14 00 00 00 C8 00 00 00 18 FF FF FF FF 00 00 00 00

(TCP)来自:127.0.0.1:50935 收到:20(Bytes) 时间:2020/2/29 13:34:42 
数据:00 00 00 14 00 00 00 C8 00 00 00 18 FF FF FF FF 00 00 00 00 
服务器自动回复:127.0.0.1 
数据:00 00 00 14 00 00 00 C8 00 00 00 18 FF FF FF FF 00 00 00 00

(TCP)来自:127.0.0.1:50935 收到:20(Bytes) 时间:2020/2/29 13:38:12 
数据:00 00 00 14 00 00 00 C8 00 00 00 18 FF FF FF FF 00 00 00 00 
服务器自动回复:127.0.0.1 
数据:00 00 00 14 00 00 00 C8 00 00 00 18 FF FF FF FF 00 00 00 00

下面是报错的日志:

02-29 14:57:36.151 6883-6915/com.tencent.mars.sample E/mars::stn: [longlink_task_manager.cc, __RunOnTimeout, 226]:task first-pkg timeout taskid:11,  nStartSendTime=14264, nfirstpkgtimeout=12
02-29 14:57:36.151 6883-6915/com.tencent.mars.sample D/mars::stn: [dynamic_timeout.cc, __StatusSwitch, 185]:task_status:-1, good_count:0, good_time:0, dyntime_status:3, dyntime_failed_normal_count_NORMAL:0, cgi:
02-29 14:57:36.151 6883-6915/com.tencent.mars.sample V/mars::stn: [longlink_task_manager.cc, __SingleRespHandle, 404]:-> __SingleRespHandle 
02-29 14:57:36.151 6883-6915/com.tencent.mars.sample W/mars::stn: [longlink_task_manager.cc, __SingleRespHandle, 426]:task end callback  long cmdid:3, err(6, -500, -1), svr(127.0.0.1:8081, DebugIP, 192.168.8.108), cli(, 127.0.0.1, n:R11081f71052d899428, sig:0), cost(s:41, r:0, c:0, rw:12996), all:26052, retry:0, cgi:/mars/sendmessage, taskid:11, tid:7400
02-29 14:57:36.151 6883-6915/com.tencent.mars.sample V/mars::stn: [com_tencent_mars_stn_StnLogic_C2Java.cc, operator, 45]:-> operator() 
02-29 14:57:36.151 6883-6915/com.tencent.mars.sample V/mars::stn: [com_tencent_mars_stn_StnLogic_C2Java.cc, operator, 45]:<- operator() +0, 
02-29 14:57:36.151 6883-6915/com.tencent.mars.sample V/mars::stn: [com_tencent_mars_stn_StnLogic_C2Java.cc, operator, 387]:-> operator() 
02-29 14:57:36.152 6883-6915/com.tencent.mars.sample V/mars::stn: [com_tencent_mars_stn_StnLogic_C2Java.cc, operator, 387]:<- operator() +0, 
02-29 14:57:36.152 6883-6915/com.tencent.mars.sample V/mars::stn: [longlink_task_manager.cc, __SingleRespHandle, 404]:<- __SingleRespHandle +0, 
02-29 14:57:36.152 6883-6915/com.tencent.mars.sample I/mars::stn: [longlink.cc, Disconnect, 246]:_scene:10007
02-29 14:57:36.152 6883-6915/com.tencent.mars.sample V/mars::comm: [dns.cc, Cancel, 289]:-> Cancel 
02-29 14:57:36.152 6883-6915/com.tencent.mars.sample V/mars::comm: [dns.cc, Cancel, 289]:<- Cancel +0, 
02-29 14:57:36.152 6883-6915/com.tencent.mars.sample V/mars::comm: [dns.cc, Cancel, 289]:-> Cancel 
02-29 14:57:36.152 6883-6915/com.tencent.mars.sample V/mars::comm: [dns.cc, Cancel, 289]:<- Cancel +0, 
02-29 14:57:36.153 6883-7400/com.tencent.mars.sample V/mars::comm: [platform_comm.cc, getNetInfo, 131]:-> getNetInfo 
02-29 14:57:36.153 6883-7400/com.tencent.mars.sample V/mars::comm: [platform_comm.cc, getNetInfo, 146]:netInfo= 1
02-29 14:57:36.153 6883-7400/com.tencent.mars.sample V/mars::comm: [platform_comm.cc, getNetInfo, 131]:<- getNetInfo +0, 
02-29 14:57:36.153 6883-7400/com.tencent.mars.sample V/mars::comm: [platform_comm.cc, getCurWifiInfo, 241]:-> getCurWifiInfo 
02-29 14:57:36.153 6883-7400/com.tencent.mars.sample V/mars::comm: [platform_comm.cc, getCurWifiInfo, 241]:<- getCurWifiInfo +0, 
02-29 14:57:36.153 6883-7400/com.tencent.mars.sample W/mars::stn: [longlink.cc, __RunReadWrite, 571]:task socket close sock:40, user disconnect:10007, nread:0, nwrite:0, net_type:R11081f71052d899428task socket close getsocktcpinfo:tcpi_state=0x1, tcpi_ca_state=0x0, tcpi_retransmits=0x0, tcpi_probes=0x0, tcpi_backoff=0x0, tcpi_options=0x7, tcpi_rto=0x33450, tcpi_snd_mss=0x56C, tcpi_rcv_mss=0x218, tcpi_unacked=0x0, tcpi_sacked=0x0, tcpi_lost=0x0, tcpi_retrans=0x0, tcpi_fackets=0x0, tcpi_last_data_sent=0x32C8, tcpi_last_ack_sent=0x0, tcpi_last_data_recv=0x32BE, tcpi_last_ack_recv=0x32C8, tcpi_pmtu=0xFFFF, tcpi_rcv_ssthresh=0x6D60, tcpi_rtt=0x60, tcpi_rttvar=0xA4, tcpi_snd_ssthresh=0x7FFFFFFF, tcpi_snd_cwnd=0xA, tcpi_advmss=0x56C, tcpi_reordering=0x3, tcpi_rcv_rtt=0x0, tcpi_rcv_space=0x6D60, tcpi_total_retrans=0x
02-29 14:57:36.154 6883-7400/com.tencent.mars.sample V/mars::comm: [platform_comm.cc, stopAlarm, 64]:-> stopAlarm
xfb7svmp

xfb7svmp3#

我也发现了这个问题。在代码里longlink.cc里。心跳包只要超时,立马断开重连
代码:

_alarm.Start(need_active_timeout ? (5* 1000) : (8 * 1000));

然后在退出循环。

if (nooping && alarmnooptimeout.Status() == Alarm::kOnAlarm) {

感觉和他们 写的文档有很大的出路

补充:
我发现原因了,有一个longlink_noop_isresp 函数指针需要实现。判断接收回来的包是否是心跳包。由于我们的服务器发送的心跳cmdid和收接的心跳cmdid 不一样,而参考代码是一样的。

相关问题