beetlex-io / XRPC

dotnet high performance remote interface and delegate invoke(RPC) communication components,support millions RPS remote interface method invokes
Apache License 2.0
84 stars 22 forks source link

Session信息丢失 #35

Closed zzeric closed 2 years ago

zzeric commented 2 years ago

在业务登录的方法里, public Task Login(string name, string password) { //测试不检查用户名密码 var event_token = XRPCServer.EventToken; event_token.Session.Name = name; //对登录成功的把用户名写到session里 IDataComClient client = event_token.Server.GetClient(event_token.Session); OnlineClients[name] = client; Console.WriteLine(name + " login,session="+event_token.Session); return Task.FromResult("ok"); }

在服务器的RPCDisconnect里 server.RPCDisconnect += (s, e) => { var username = e.Session.Name; Console.WriteLine(username + " disconnected"); if (username != null) { IDataComClient client = null; OnlineClients.TryRemove(username, out client); } };

现在测试客户端连接一段长时间后会出现打印用户名为空的“disconnected”。如果客户端短时间连接后断开,用户名不会丢失。可能说明client的Tcp连接发生过自动重连后Session信息丢失的情况。

beetlex-io commented 2 years ago

Session只针对当前TCP连接并不会持久化