[英]How do I connect an AppSession to a server with SuperSocket?
我正在使用SuperSocket建立新的客戶端-服務器-網絡,並且無法將AppSession
連接到服務器。
我發現了這個問題 ,並為我的程序嘗試了它。
服務器運行正常,但目前我只能與“ AsynTcpSession”連接。 當我檢查連接的會話時,它在服務器上顯示為“ AppSession”。 我想使用“ AppSession”,因為您可以給他們自定義參數。
我創建的AppSession:
public class MyAppSession : AppSession<MyAppSession, MyRequestInfo>
{
// those parameter
public int ClientKey { get; set; }
public string HashKey { get; set; }
}
服務器:
MyAppServer _server = new MyAppServer();
ServerConfig _socketServerConfig = new ServerConfig { ReceiveBufferSize = 5000, MaxRequestLength = 5000, Name = "Test- Server", SendingQueueSize = 5000, ServerType = "MyAppServer", Port = 6000};
if (_server.Setup(_socketServerConfig))
{
DoStuff();
}
客戶:
ClientSession _gateway = new AsyncTcpSession();
_gateway.Connect(6000);
在收到客戶的電報時:
private void ReceivedDataFromClient(MyAppSession session, MyRequestInfo requestinfo)
{
// session.SocketSession contains the Client AsynTcpSession
}
編輯:
AppSession
具有一個void Initialize(IAppServer<TAppSession, TRequestInfo> appServer, ISocketSession socketSession)
-函數。 如何使用? 會話僅知道服務器的IP和端口。
AsynTcpSession和AppSession是不同的東西,盡管它們都被稱為“會話”。
任何客戶端連接包/類都與AppSession無關。 (例如AsynTcpSession)
AppSession只是AppServer客戶端連接的臨時存儲。 讓AppServer控制客戶端連接,識別每個客戶端,控制連接池...等。 您可以在AppSession中定義許多變量,但是要仍然通過自己的代碼分配值(客戶端應發送這些信息)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.