private void ConnectionProcess(TcpSocketSaeaSession session) { if (Interlocked.Exchange(ref _manager_login, 1) == 0) { this.SendAck(session, SessionWorkType.ManagerSession); _manager_session = session; session.AppTokens = new object[] { SessionWorkType.ManagerSession, null }; //获取所有主连接 SendMessageHelper.SendMessage(session, MsgCommand.Msg_Pull_Session); } else { this.SendAck(session, SessionWorkType.ManagerWorkSession); var sessionBased = new TcpProxySessionBased(session); session.AppTokens = new object[] { SessionWorkType.ManagerWorkSession, sessionBased }; this._onSessionNotifyProc(SessionCompletedNotify.OnConnected, sessionBased as SessionHandler); } }
public override void SendAsync(byte[] data, int offset, int length) { if (this._disposable == 1) { return; } byte[] bytes = CompressHelper.Compress(data, offset, length); if ((SessionWorkType)_session.AppTokens[0] == SessionWorkType.ManagerSession) { byte[] body = new byte[sizeof(Int64) + sizeof(Int32) + bytes.Length]; BitConverter.GetBytes(this.RemoteId).CopyTo(body, 0); BitConverter.GetBytes(bytes.Length).CopyTo(body, 8); bytes.CopyTo(body, 12); SendMessageHelper.SendMessage(_session, MsgCommand.Msg_MessageData, body); } else { byte[] body = new byte[bytes.Length + sizeof(Int32)]; BitConverter.GetBytes(bytes.Length).CopyTo(body, 0); bytes.CopyTo(body, 4); _session.SendAsync(body, 0, body.Length); } }
public override void SessionClose() { if (this._disposable == 1) { return; } if ((SessionWorkType)_session.AppTokens[0] == SessionWorkType.ManagerSession) { SendMessageHelper.SendMessage(_session, MsgCommand.Msg_Close_Session, BitConverter.GetBytes(this.RemoteId)); } else { _session.Close(true); } }
private void CreateSession(byte[] data) { byte[] body = new byte[data.Length - 1]; Array.Copy(data, 1, body, 0, body.Length); //byte[] sessionIds = new byte[body.Length * 2]; List <byte> buffer = new List <byte>(); byte[] sessionId = new byte[sizeof(Int64) * 2]; List <TcpProxySessionBased> sessionList = new List <TcpProxySessionBased>(); for (int i = 0; i < body.Length / sizeof(Int64); i++) { Array.Copy(body, i * sizeof(Int64), sessionId, 0, sizeof(Int64)); TcpProxySessionBased sessionBased = new TcpProxySessionBased(_manager_session); sessionBased.RemoteId = BitConverter.ToInt64(sessionId, 0); Console.WriteLine("CreateSession:" + sessionBased.RemoteId + " Id:" + sessionBased.Id); sessionList.Add(sessionBased); BitConverter.GetBytes(sessionBased.Id).CopyTo(sessionId, sizeof(Int64)); buffer.AddRange(sessionId); //Array.Copy(sessionId, 0, sessionIds, i * (sizeof(Int64) + sizeof(Int64)), sizeof(Int64) + sizeof(Int64)); } SendMessageHelper.SendMessage(_manager_session, MsgCommand.Msg_Set_Session_Id, buffer.ToArray()); this._sessionList.AddRange(sessionList.ToArray()); foreach (var session in sessionList) { this._onSessionNotifyProc?.Invoke(SessionCompletedNotify.OnConnected, session as SessionHandler); } sessionList.Clear(); }