Skip to content

Commit

Permalink
drop older package
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwu committed Apr 17, 2015
1 parent 188d0e9 commit 2599323
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions server/udpserver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function response.register(service, key)
room = snax.bind(service, "room"),
address = nil,
time = skynet.now(),
lastevent = nil,
}
return SESSION
end
Expand Down Expand Up @@ -69,7 +70,11 @@ local function udpdispatch(str, from)
elseif eventtime > s.time then
-- drop this package, and force time sync
return timesync(session, localtime, from)
elseif s.lastevent and eventtime < s.lastevent then
-- drop older event
return
end
s.lastevent = eventtime
s.room.post.update(str:sub(9))
else
snax.printf("Invalid session %d from %s" , session, socket.udp_address(from))
Expand Down

2 comments on commit 2599323

@davewang
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个timesync有bug,在(局域网)做同步数据频繁会造成丢包,貌似是 timesync(session, localtime, from) 的问题, 之前ios里用apple的Game Center Multiplayer做同步也没有丢包问题何况Game Center还是外网,最后把相关time.sync的代码注释掉,直接做转发同步就ok了。

@cloudwu
Copy link
Owner Author

@cloudwu cloudwu commented on 2599323 May 2, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

udp 丢包是必须考虑的。所以这是一个特性。

Please sign in to comment.