我正在.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, data.Length);
using (var buffer = new MemoryStream())
{
byte[] chunk = new byte[4096];
int bytesRead;
while ((bytesRead = stream.Read(chunk, 0, chunk.Length)) > 0)
{
buffer.Write(chunk, 0, bytesRead);
}
data = buffer.ToArray();
}
}
//I used this also with same result -> no respond
//SimpleMLLP
/*
var connection = new SimpleMLLPClient(localIP, localPort,
Encoding.UTF8);
var response = connection.SendHL7Message(req);
*/
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
Console.ReadLine();
}
}
所以我体验到 TCP 中的缓冲区大小为 0(由于超时)。在 SimpleMLLP 测试中,SendHK7Message 方法永远不会返回