kerryjiang / SuperSocket

SuperSocket is a light weight, cross platform and extensible socket server application framework.
Apache License 2.0
3.95k stars 1.15k forks source link

怎么从服务器发送消息 #755

Closed Leblanc2025 closed 3 weeks ago

Leblanc2025 commented 1 month ago

public class UserSession : SuperSocket.Server.AppSession { } 我的UserSession类继承了AppSession,但是AppSession无法调用SendAsync()函数,因为AppSession中该函数不是public的

Leblanc2025 commented 1 month ago

版本2.0.0.beta27

7haihai commented 1 month ago
    private IConnection _connection;

    protected internal IConnection Connection
    {
        get { return _connection; }
    }

AppSession有这个,Connection.SendAsync(xxx)

    ValueTask IAppSession.SendAsync(ReadOnlyMemory<byte> data, CancellationToken cancellationToken)
    {
        return _connection.SendAsync(data, cancellationToken);
    }

    ValueTask IAppSession.SendAsync<TPackage>(IPackageEncoder<TPackage> packageEncoder, TPackage package, CancellationToken cancellationToken)
    {
        return _connection.SendAsync(packageEncoder, package, cancellationToken);
    }

我用的这个, image

Leblanc2025 commented 1 month ago

@7haihai 谢谢您,已经解决。 public async Task SendAsync(byte[] data) { await Connection.SendAsync(send); }