简体   繁体   中英

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.

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'. When I check the connected sessions it is shown as an 'AppSession' at the server. I want to use 'AppSession', because you can give them custom parameter.

My created 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. How do I use it? The session only knows the server ip and port.

AsynTcpSession and AppSession are different things, althought they are all called 'session'.

Any client connection packages / classes have no matter with AppSession. (eg. AsynTcpSession)

The AppSession just a temporary storage of client connection for AppServer. Let the AppServer controlls the client connections, identify each clients, controll the connections pool...etc. You can define many variables in the AppSession, But to assign values will still by your own codes (and client should send these informations).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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