我正在.Net 中实现一个应用程序。我必须通过 SSH 创建连接,该连接有效,但 HL7 数据接收失败。目的地是树莓派。因此,当我调试 ssh 客户端已连接时,端口已转发,tcp 客户端也已连接,但我的查询没有答案。请给我推荐一些例子!
在这个项目中,我已经在 Android 上实现了它 - 它工作得很好。所以在.Net中我尝试了NHapiTools库,我也尝试了直接的TcpClient方式。本地端口 = 远程端口。我用的是 localIP = "localhost"
static void Main(string[] args)
{
try
{
PrivateKeyFile file = new PrivateKeyFile(@"./key/private.key");
using (var client = new SshClient(remoteIP, sshPort, username, file))
{
client.Connect();
var ci = client.ConnectionInfo;
var port = new ForwardedPortLocal(localIP, localPort, client.ConnectionInfo.Host, remotePort);
client.AddForwardedPort(port);
port.Start();
var req = "MSH|^~\\&|TestAppName||AVR||20181107201939.357+0000||QRY^R02^QRY_R02|923456|P|2.5";
////TCP
var tcpClient = new TcpClient();
tcpClient.Connect(localIP, (int)localPort);
Byte[] data = System.Text.Encoding.ASCII.GetBytes(req);
using (var stream = tcpClient.GetStream())
{
stream.Write(data, 0, …Run Code Online (Sandbox Code Playgroud)