简体   繁体   English

如何使用SuperSocket将AppSession连接到服务器?

[英]How do I connect an AppSession to a server with SuperSocket?

I'm setting up a new client-server-network with SuperSocket and can't connenct an AppSession to the server. 我正在使用SuperSocket建立新的客户端-服务器-网络,并且无法将AppSession连接到服务器。

I found this question and tried it for my program. 我发现了这个问题 ,并为我的程序尝试了它。

The server is running fine, but at the moment I can only connect with the 'AsynTcpSession'. 服务器运行正常,但目前我只能与“ AsynTcpSession”连接。 When I check the connected sessions it is shown as an 'AppSession' at the server. 当我检查连接的会话时,它在服务器上显示为“ AppSession”。 I want to use 'AppSession', because you can give them custom parameter. 我想使用“ AppSession”,因为您可以给他们自定义参数。

My created AppSession: 我创建的AppSession:

public class MyAppSession : AppSession<MyAppSession, MyRequestInfo>
{
// those parameter
public int ClientKey { get; set; }

public string HashKey { get; set; }
}

Server: 服务器:

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();
}

Client: 客户:

ClientSession _gateway = new AsyncTcpSession();
_gateway.Connect(6000);

On receiving telegram from Client: 在收到客户的电报时:

private void ReceivedDataFromClient(MyAppSession session, MyRequestInfo requestinfo)
{
// session.SocketSession contains the Client AsynTcpSession
}

EDIT: 编辑:

The AppSession has an void Initialize(IAppServer<TAppSession, TRequestInfo> appServer, ISocketSession socketSession) -Function. AppSession具有一个void Initialize(IAppServer<TAppSession, TRequestInfo> appServer, ISocketSession socketSession) -函数。 How do I use it? 如何使用? The session only knows the server ip and port. 会话仅知道服务器的IP和端口。

AsynTcpSession and AppSession are different things, althought they are all called 'session'. AsynTcpSession和AppSession是不同的东西,尽管它们都被称为“会话”。

Any client connection packages / classes have no matter with AppSession. 任何客户端连接包/类都与AppSession无关。 (eg. AsynTcpSession) (例如AsynTcpSession)

The AppSession just a temporary storage of client connection for AppServer. AppSession只是AppServer客户端连接的临时存储。 Let the AppServer controlls the client connections, identify each clients, controll the connections pool...etc. 让AppServer控制客户端连接,识别每个客户端,控制连接池...等。 You can define many variables in the AppSession, But to assign values will still by your own codes (and client should send these informations). 您可以在AppSession中定义许多变量,但是要仍然通过自己的代码分配值(客户端应发送这些信息)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM