|
|
@@ -19,11 +19,13 @@ type ClientSessionCb struct {
|
|
|
}
|
|
|
|
|
|
func (self *ClientSessionCb) OnClosed(ses nnet.ISession, reason int32) {
|
|
|
- fmt.Fprintf(os.Stdout, "lost connection %v, reason:%v\n", ses.GetRawConn().RemoteAddr(), reason)
|
|
|
- clt.StartReconn()
|
|
|
+ fmt.Printf("session num: %d\n", clt.GetSessionNum())
|
|
|
+ fmt.Fprintf(os.Stdout, "lost connection %v, id:%v, reason:%v\n", ses.ServerAddr(), ses.Id(), reason)
|
|
|
+ clt.StartReconn(ses.ServerAddr(), ses.Id())
|
|
|
}
|
|
|
|
|
|
func (self *ClientSessionCb) OnConnected(ses nnet.ISession) (bool, int32) {
|
|
|
+ fmt.Printf("connected to %s\n", ses.ServerAddr())
|
|
|
return true, 0
|
|
|
}
|
|
|
|
|
|
@@ -48,7 +50,7 @@ func (self *ClientSessionCb) OnHeartbeat(ses nnet.ISession) bool {
|
|
|
|
|
|
func start_tcp_client() {
|
|
|
__start_client(func() nnet.IHub {
|
|
|
- clt := cpn.NewTcpClient(&nnet.DefHubConfig, &ClientSessionCb{}, &TcpProtocol{}, cpn.WithReconn(time.Second))
|
|
|
+ clt := cpn.NewTcpClient(&nnet.DefHubConfig, &ClientSessionCb{}, &TcpProtocol{}, cpn.WithReconn(3*time.Second))
|
|
|
err := clt.NewConnection(SERVER_ADDR, 5)
|
|
|
if err != nil {
|
|
|
panic(err)
|
|
|
@@ -59,7 +61,7 @@ func start_tcp_client() {
|
|
|
|
|
|
func start_ws_client() {
|
|
|
__start_client(func() nnet.IHub {
|
|
|
- clt := cpn.NewWsClient(&nnet.DefHubConfig, &ClientSessionCb{}, &WsProtocol{}, cpn.WithReconn(time.Second))
|
|
|
+ clt := cpn.NewWsClient(&nnet.DefHubConfig, &ClientSessionCb{}, &WsProtocol{}, cpn.WithReconn(3*time.Second))
|
|
|
u := url.URL{
|
|
|
Scheme: "ws",
|
|
|
Host: SERVER_ADDR,
|