public Session CreateSession(IPEndPoint remoteAddress) { if (sessions.ContainsKey(remoteAddress)) { throw new Exception("session already exists"); } var random = new Random(); var session = new Session { CreatedDate = DateTimeOffset.Now, Heartbeat = DateTimeOffset.Now, SessionID = (ushort)random.Next(ushort.MaxValue), Key = (ushort)random.Next(ushort.MaxValue) }; Logger.Info(string.Format("{0} SESSION : {1}, Key {2}", remoteAddress, session.SessionID, session.Key)); sessions.Add(remoteAddress, session); return session; }
public static void AddSession(this UdpMessage message, Session session) { message.Session = session.SessionID; message.Key = session.Key; }