我有一个在 Linux 上运行的服务器应用程序。这个应用程序是 使用 protobuf c 和 protobuf.rpc.c 文件开发用于 RPC 通信。
我有一个在 Windows 上运行的客户端应用程序。它是用 c# 开发的,使用 protobuf-net.dll 和 ProtobufRemote.dll 进行 RPC 通信。这两个应用程序使用具有相同服务方法的相同 proto 文件。
我可以使用以下代码从 C# 客户端应用程序创建代理。
using System.Configuration;
using System.Net.Sockets;
using ProtoBufRemote; // rpc reference
using StarCall; // proto file
#region Create client connection
Int32 port = Convert.ToInt32(ConfigurationManager.AppSettings["PORT"]);
TcpClient tcpClient = new TcpClient(ConfigurationManager.AppSettings["SERVERIP"].ToString(), port);
var controller = new RpcController();
var client = new RpcClient(controller);
var channel = new NetworkStreamRpcChannel(controller, tcpClient.GetStream());
channel.Start();
var service = client.GetProxy<Istarcall_services>();
if (service == null)
Console.WriteLine("error creating client..");
//now calls can be made, they will block until a result is received
Console.WriteLine("Client connected to Server....\n");
#endregion
但是每当我尝试从 C# 客户端应用程序调用服务方法(如下所示)时,该应用程序就会挂起并且无法从 Linux C 服务器应用程序获得任何响应。
try
{
Room_Config room = new Room_Config();
room.Room_Dial_Num = 1;
Room_Config roomRet = service.read_room(room); // service method
}
catch (Exception)
{
throw;
}
应用程序卡在下面的代码中。
protected RpcMessage.Parameter EndAsyncCallHelper(string methodName, IAsyncResult asyncResult)
{
PendingCall pendingCall = (PendingCall)asyncResult;
pendingCall.AsyncWaitHandle.WaitOne(); // application hanging here
pendingCall.AsyncWaitHandle.Close();
if (pendingCall.IsFailed)
throw new InvalidRpcCallException(serviceName, methodName,
String.Format("Server failed to process call, returned error message: \"{0}\".",
pendingCall.ServerErrorMessage));
return pendingCall.Result;
}
根据上述场景,我有以下疑问。
这个protobuf远程c# dll是否可以帮助从linux c代码创建通信。如果没有,请帮助我如何使用 linux c 代码创建通信 channel 。
请提供是否有任何替代 rpc dll,以便 c# 客户端应用程序与 linux protobuf c 和 protobuf rpc.c 文件进行通信。
请告诉我上述方法是否错误,并使用合适的解决方案进行纠正。
请帮帮我。如果不清楚,请发送到下面提到的邮箱。
最佳答案
您是否已使用 https://code.google.com/p/protobuf-remote/ 上提供的 ProtoBufRemote cpp 在 Linux 中实现了您的服务器??
如果是,那么您必须替换或修改 SocketRpcChannel.cpp 类,因为它使用不适用于 Linux 的 WinSock2。 你这样做了吗?如果是,请分享您在服务器中使用的修改后的 SocketRpcChannel 类。
谢谢。
关于windows - Windows 上运行的 C# 与 linux 上运行的 C 通过 protobuf 进行通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9925427/