Click here to Skip to main content
15,885,435 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a server application running on Linux. This application was
developed using protobuf c and protobuf.rpc.c files for RPC communication.

I have a client application which was running on windows.It was developed in c# using protobuf-net.dll and ProtobufRemote.dll for RPC communication.Both application using the same proto file having same service methods.

I can able to create a proxy from C# client application with the below code.

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


But whenever I am trying to invoke a service method from C# client application as shown below, the application is hanging and not getting any response from Linux c server application.



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;
       }


The application is hanging in the below code.

C#
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;
            }


According to above mentioned scenarios, I have the following queries.

1. Whether this protobuf remote c# dll can help to create a communicatgion from the linux c code. If not please help me how to create a communication channel with the linux c code.

2. Please provide if any alternative rpc dll for c# client application to communicate to linux protobuf c and protobuf rpc.c file.

3. Please tell me if my above approach is wrong and rectify with the suitable solution.

Please help me out. If not clear please send to mail mentioned below.
Posted

1 solution

At this moment, I can answer only one partial question: about the alternative, but this alternative could be critically important for you to make a decision.

You can use C#, more exactly, CLR solution on both sides: Windows and Linux. For Linux, you can run .NET code using Mono. Please see:
http://en.wikipedia.org/wiki/Mono_%28software%29[^],
http://www.mono-project.com/Main_Page[^].

To see how it can your task could be compatible with Mono, let's look at the means of networking available for .NET. Let me list your options, low-level to high level:

Sockets. Use the class System.Net.Sockets.Socket for TCP or UDP socket programming.

TCP. Use the classes System.Net.Sockets.TcpListener in server side, System.Net.Sockets.TcpClient of client side. I would say, this is a better option.

Remoting or WCF. See overview and technology samples in MSDN.
The namespace System.Net is standardized under ECMA and fully implemented in Mono. WCF is not standard, but it is also implemented in Mono, in most parts. WCF and remoting could be most interesting as concerns to your question, because this is something like object-oriented reincarnation of RPC.

If you still need to have the rest of your Linux project in C or C++, you can do it. You still need to implement the application in Mono and host your native Linux (C or C++) code in it using P/Invoke.

If you need to learn P/Invoke, please see:
http://en.wikipedia.org/wiki/P/Invoke[^],
http://msdn.microsoft.com/en-us/library/Aa712982[^].

This CodeProject article can also be useful:
Essential P/Invoke[^].

At least think about it. In could save you from major interoperability problems.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900