查看来自此来源的关于 C 示例的部分。
核心 C 客户端是一个套接字接收器。
如果您需要功能齐全的客户端,我建议在我最初的评论中使用解决方法
您可以在 Raspberry Pi 上使用标准客户端,并在 Raspberry Pi 上构建一个新的网络服务,您可以从 c# 以更标准的方式连接到该服务”
C# 监听器
否则,您可以尝试只创建一个基本的 C# 侦听器:按照 msdn How-To 操作。
public void createListener()
{
// Create an instance of the TcpListener class.
TcpListener tcpListener = null;
IPAddress ipAddress = Dns.GetHostEntry("localhost").AddressList[0];
try
{
// Set the listener on the local IP address
// and specify the port.
tcpListener = new TcpListener(ipAddress, 13);
tcpListener.Start();
output = "Waiting for a connection...";
}
catch (Exception e)
{
output = "Error: " + e.ToString();
MessageBox.Show(output);
}
while (true)
{
// Always use a Sleep call in a while(true) loop
// to avoid locking up your CPU.
Thread.Sleep(10);
// Create a TCP socket.
// If you ran this server on the desktop, you could use
// Socket socket = tcpListener.AcceptSocket()
// for greater flexibility.
TcpClient tcpClient = tcpListener.AcceptTcpClient();
// Read the data stream from the client.
byte[] bytes = new byte[256];
NetworkStream stream = tcpClient.GetStream();
stream.Read(bytes, 0, bytes.Length);
SocketHelper helper = new SocketHelper();
helper.processMsg(tcpClient, stream, bytes);
}
}
整个详细的实现将超出这里的范围。
旁注
请记住,您需要在循环时睡觉。
可能更简单的解决方案
但是,乍一看,利用本机客户端绑定似乎是更简单的方法。
例如,gps_read()
描述为
阻止从守护进程读取数据。
这里的想法是从 C# 调用C++ 包装器并编写客户端的单元操作,如其他答案中所述