ccding / go-stun

A go implementation of the STUN client (RFC 3489 and RFC 5389)
Apache License 2.0
663 stars 120 forks source link

stun punching invalid a few minutes later #28

Closed nkbai closed 4 years ago

nkbai commented 6 years ago

if I use the punchd port as a udp server ,a few minutes later, it will fail. it needs a keep alive method. the keepalive method can not cooperate with a server connection, because when keep alive called, this method will send and receive packet. generally , there only one postion for receiving packet!

AudriusButkevicius commented 6 years ago

You need to implement this yourself and do filtering, I don't think there is a way around it.

nkbai commented 6 years ago

do you mean that impement another keepalive method myself?

AudriusButkevicius commented 6 years ago

Well, you can either use the existing one provided by the library, and filter out packets coming back, or do an application level keepalive, by trying to reconnect to some node every 24seconds.

nkbai commented 6 years ago

for the first way: but there are two problem 1: i can filter packets for comming back, but your keepalive method change the property of the connection, it calls setreaddeadline

  1. the keepalive method will receive many my own packets , which makes my protocol error.

that's why i want sending stun request only

nkbai commented 6 years ago

the second way is ok, but there is no relation with this keepalive method.

AudriusButkevicius commented 6 years ago

But you can already implement keepalives in your own application, sending a random packet somewhere, or doing it at your protocol level.