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

下面的EasyClient发送数据服务端接收不到呢 #730

Closed 107295472 closed 6 months ago

107295472 commented 6 months ago
.AddServer<SuperSocketServiceA, TextPackageInfo, LinePipelineFilter>(builder =>
{
    builder
        .UseSession<MyAppSession>()
        //.UsePackageDecoder<MyPackageDecoder>()
        .UsePackageHandler(
            async (session, package) =>
            {
                Console.WriteLine(package.Text);
                //发送给websocket端
                foreach (var item in App.webSession)
                {
                    await item.SendAsync(package.Text);
                }
            }
        )
        .ConfigureServerOptions(
            (ctx, config) =>
            {
                return config.GetSection("TestServer1");
            }
        )
        .ConfigureLogging(
            (hostCtx, loggingBuilder) =>
            {
                loggingBuilder.AddConsole();
            }
        );
})
var client = new EasyClient<TextPackageInfo>(new LinePipelineFilter()).AsClient();

if (!await client.ConnectAsync(new IPEndPoint(IPAddress.Loopback, 4040)))
{
    Console.WriteLine("Failed to connect the target server.");
    return;
}
if (client != null)
{
    await client.SendAsync(Encoding.UTF8.GetBytes("ftestt-------------22111\r\n"));
}

Console.ReadLine();
wj8400684 commented 6 months ago

CommandLinePipelineFilter试试

107295472 commented 6 months ago

CommandLinePipelineFilter要用到StringPackInfo,要对方得有key,body,不易对接别人的包啊

AlianBlank commented 6 months ago

我用这个也有问题。我现在使用的是AsyncTcpSession

ygr757326 commented 6 months ago

连接成功后,要设置开始接收: client.StartReceive(); 然后 再 await client.SendAsync(……)。 我也是测试了很长时间才发现这个问题。 @kerryjiang