19.Using ProudNet with other languages than C++

19.1C# Language Support

In order to use ProudNet in C#, we wrap native modules with SWIG.

Surely PIDL compiler of 4. Remote Method Invocation can create proxy and stub in C#. Therefore, you can develop application programs by C# which includes RMI functions.

How to create a C# Project

To make ProudNet available to the C# project you created, set the DLL files as shown on the page below. And add ProudDotNetClient.dll to reference for client, add ProudDotNetClient.dll & ProudDotNetServer.dll to reference for server.

http://guide.nettention.com/csharp_en#dotnetframeworkdll

You can develop with DotNet Framework as well as DotNet Core using ProudNet.

Please refer to the page at the link below for how to make a DotNet Core project using ProudNet run on Linux.

http://guide.nettention.com/csharp_en#linuxdotnetcoreserver

If the C # project you created has been set up to use ProudNet,

You can use ProudNet in C # while referring to 'How to use C#' on the link page below.

http://guide.nettention.com/csharp_en

In addition, we would appreciate your reference to the C # language support example listed in the link below.

The samples for using ProudNet with C# can be found at 10. Sample codes of using ProudNet in C#.

How to use PIDL compiler in C#

You can use 4. Remote Method Invocation in C#. And for this, PIDL compiler can create proxy and stub code of C#. If you execute as below, proxy and stub code of C# will be created. (Existing –clr is same as -cs)

PIDL.exe -cs <input-file-name>

When developing an application program, there would be a module that is commonly used between server and client. The proxy and stub code of C# should be placed in that common module. And for this module, you should custom build C# project after receiving PIDL file same as 11.2 How to run PIDL Compiler. In order to do this, please refer to below.

그림 19-1How to set a custom build for PIDL file from C# project

Proxy and stub created by building C2S.pidl are as below.

C2S_common.cs
C2S_proxy.cs
C2S_stub.cs

You should include them as source files at C# project(.csproj). But, please be reminded that these files are the build outcomes only, not user-written sources. So they shouldn't be included in your source control (i.e. SVN). Otherwise, it could prompt a writing error at a read-only file.

It is recommended to open .csproj in an editor and modify like this below.

<Target Name="BeforeBuild">
<ItemGroup>
<Compile Include="C2S_common.cs" />
<Compile Include="C2S_proxy.cs" />
<Compile Include="C2S_stub.cs" />
</ItemGroup>

</Target>
<Target Name="AfterBuild">
</Target>

The class names of Proxy and stub created by C# are same with those of C++. And the usage is also identical. (Refer to 11.3 Attaching RMI proxy and stub)

For more details, please refer to the common module source from 10. Sample codes of using ProudNet in C#.

C# Marshaling user-defined type in C#

2. Marshaling PIDL parameter type shows how you can set use define object type on RMI parameter, which also works with C#.

For the method of marshalling in C #, please refer to the page contents of the link below.

http://guide.nettention.com/csharp_en#marshalling

public, internal, private attribute for RMI proxy, stub classes

Proxy, stub and common classes generated by PIDL compiler have 'internal' access modifier by default. So they can be used by other source files in a same module(aka. assembly), but not by other modules.

However, you may want to change access modifier to 'public' when you are making a module which has these classes and other modules which use them.

In this case, set the access modifier attribute like this below for PIDL compilation.

// This will let proxy, stub and common classes to have access modifier 'public'.
[marshaler(clr)=MyMarshaler, access=public]
global MyC2S 3000
{
    Foo(...);
}

Communicating between programs written by C# and C++

Please refer to 19.2 Communicating between programs written in other languages than C# and C++ .

19.2Communicating between programs written in other languages than C# and C++

There could be cases where you want to write program using two different languages and still communicate between programs using ProudNet. To make this happen, all it takes is to generate proxy and stub from each programs.

For basic type such as int, double, string and etc, ProudNet provides a wrapping module that works in other languages then C++. But name for these basic types may be different between programs. For instance, the string class of C# is System.String but in C++, it is std::string, std::wstring, ATL::CString, Proud::String.

To fix this problem, PIDL compiler offers a function that you can alter variable type from proxy and stub when they are being generated in correspondence to language you use.

Here is the sample.

// When generating proxy,stub in C#, change the name of TypeA to TypeB.
rename cs(TypeA,TypeB);
// When generating proxy,stub in C++, change the name of TypeC to TypeD.
rename cpp(TypeC,TypeD);

global XXX 2000
{
Foo([in]TypeA a);  // When generating proxy,stub in C#, it becomes Foo(TypeB a).
Goo([in]TypeC c);  // When generating proxy,stub in C++, it becomes Goo(TypeD c).
}