如何将消息发送到红隼中的套接字?

问题描述 投票:0回答:0

我通过

kestrel
听过两个本地端口,效果很好。

webBuilder
    .UseKestrel(opt =>
    {
        // http request
        opt.ListenLocalhost(5000);
        // simple tcp communication with stm32-based device
        opt.Listen(IPAddress.Parse("192.168.1.2"), 501, opt =>
        {
            opt.UseConnectionHandler<MyTcpHandler>();
        });
    })
    .UseStartup<Startup>();
});

但是如何向与指定 ip(socket) 连接的设备发送消息

[HttPost("devices/{id}")]
public Task Send(int id, string msg)
{
    // convert id to ipendpoint
    var ipEndPoint = ipEndPoints[id];

    // get socket in kestrel by ipEndPoint 
    ??? 

    // send message
    socket.Send(Encoding.UTF8.GetString(msg));
}
c# asp.net-core kestrel-http-server
© www.soinside.com 2019 - 2024. All rights reserved.