Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Server Procedures Remote , +
Hi all,
 
I am creating one application of Remote Procedure Call where i have passed a string
but i am still not able to pass a Structure between client and server.
Please can anyone help me...
 
Thanks,
Kunal Shah
Posted 18-Jul-12 1:04am
Edited 18-Jul-12 1:10am
v2
Comments
aLcoHolicDevil at 18-Jul-12 6:11am
   
Sorry??
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You can pass your structure just as buffer, exactly like you pass the strings. But it is not very ok, because binary representation of structure may be different on server and client. IStream is COM interface, so it is available at COM level which is higher than RPC level. Anyway, IStream is for serialization, but you need marshalling.
 
That you have to know, is that some user defined structure used in RPC, should be defined at RPC level. So, you have to marshalize it. It means, you make it RPC. After passing the structure between client and server, it should be unmarshalized and used. This means, clients and servers will have always the same structure, but binary compatible with own platform. This can be done manually, or can be used some RPC compiller, which will convert function calls to RPC calls, and all the RPC marshalling routines will be hidden in proxy stub files. You will describe your structure in the RPC language, so it should exist at RPC level. In your language you will deal with mappings from RPC level to your language.
If you use Microsoft RPC, you would likely to use IDL (MIDL) do define your own structures at RPC level. And use MIDL to compile them. All the marshalling/unmarshalling routines you will have in the generated proxy and stub files.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa367080(v=vs.85).aspx[^]
  Permalink  
v4
Comments
Eugen Podsypalnikov at 18-Jul-12 8:05am
   
// Anyway, IStream is for serialization, but you need marshalling
IStream pointers can be marshaled by type library marshaling, and can be accessed by C++ clients (see the link above) :)
armagedescu at 18-Jul-12 9:27am
   
It is about IStream pointer, not about the Stream managed by IStream. This means marshalling pIstream to pIstream. This means after you unmarshall the pIStream you will be able to access the stream. But the stream itself remains the same unstructured buffer, on both, client and server. And marshaller knows nothing about how should be used an unstructured buffer.
Eugen Podsypalnikov at 18-Jul-12 9:34am
   
// And marshaller knows nothing about how should be used an unstructured buffer
Why nothing ? The in-/out- code could be shared for both sides... :)
armagedescu at 18-Jul-12 9:43am
   
It is unstructured, and it deppends on the implementation. Object serializes itself in an RPC unaware way. in/out has no warranty on correctness of transfer. For instance consider in/out on whole structure memory buffer at once.
Seralizing and marshalling make very different things, this is why they exists separated to each other.
Eugen Podsypalnikov at 18-Jul-12 9:51am
   
// It is unstructured, and it deppends on the implementation
Yes, the serializing code must be known (shared) for both sides,
as it's shown at the Figure 2 in the link above :)
armagedescu at 18-Jul-12 10:13am
   
Look at your link above again, and just think, that you have to implement in, out, reimplement again when changing the structure, and so on, чзж. Moreover you have to do it via one more layer, the COM. Much easier is pass marshalled memory buffer directly to RPC, as the IStream will solve exactly nothing in this case. IStream interface exists for COM objects and formats. While there is no COM, there is absolutely no reason to use IStream.
If user wants to pass a structure via RPC, the answer is to make it RPC. Any changes of the structure just recompile the RPC definition and recompile the program.
Eugen Podsypalnikov at 18-Jul-12 10:27am
   
// reimplement again when changing the structure
Why ? Only sizeof() will be recompiled... In case of an object the same serializing that is used for HDD exchange could do it... :)
armagedescu at 18-Jul-12 10:48am
   
No. Not only sizeoff. If you need just within same HDD exchange, then you don't need RPC at all. Anyway, doing RPC you have to think RPC.
Consider a point
struct point{int x; int y;};
Consider two systems, big endiang(BE) and little endian(LE). Structure will have different binary representation.
The method void setPoint(const point) pass an rpcpoint, but each program two systems will have just point, with different binary representation.
Suppose you want to add one more dimension to your point, make it relativistic, and add the double time.
struct point{int x; int y;double time;};
Compiller generates marshalling for bigger point, with three attributes, the proxy code marshalls now the x, the y, and the z, and the stub code does the unmarshall for the same thing. So, server program pass a point to RPC and RPC does something. After that RPC does some other thing and pass it to client as a point.
All the code generated by RPC compiller is the RPC level, so you don't really have to carry about it.
Eugen Podsypalnikov at 18-Jul-12 11:09am
   
// then you don't need RPC at all
OK, thank you :)
I did not know about BE-LE relations and even about RPC as technique as well :)
armagedescu at 18-Jul-12 9:37am
   
Anyway. IStream is COM interface. This most likely first means that you will have to initialize COM, because RPC does not have COM interfaces and type libraries built in.
Eugen Podsypalnikov at 18-Jul-12 9:46am
   
// This most likely first means that you will have to initialize COM
Yes, IStream is COM interface :)
armagedescu at 18-Jul-12 10:15am
   
But the question is about RPC. RPC exists in many places where is no Windows and no COM.
Eugen Podsypalnikov at 18-Jul-12 10:30am
   
// But the question is about RPC
You are right :)
aLcoHolicDevil at 19-Jul-12 6:03am
   
Can some one please explain it with example
armagedescu at 19-Jul-12 10:10am
   
You should define your structure at RPC level. This means to define it in RPC language, such as some kind of IDL, or other one, depending on your platform. After that you have to compile this one with provided compilers. These compillers will make C++ code, which you will use. If you use Windows RPC, then you will write your procedures in IDL and will compile with MIDL. Anyway, provide some more info about your system, compiler, kind of RPC, snippets of code.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

RPC comes in many flavours. You can use TAO[^] which is an excellent implementation of the CORBA[^] specification - and a wide range of examples are included with the download.
 
Then there is DCE RPC[^], and a variant of DCE RPC is included with Windows[^] - you will find that a number of examples are included with the SDK[^]
 
Best regards
Espen Harlinn
  Permalink  
v2
Comments
Sergey Alexandrovich Kryukov at 22-Jul-12 14:43pm
   
Did you mean to say "comes in many flavors?
Good ideas, my 5.
--SA
Espen Harlinn at 22-Jul-12 14:45pm
   
I may inadvertently left out the n, thanks Sergey :-D
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try to pass an IStream pointer
after the writing of the structure into its content Smile | :)
 
See also: Transferring Data with Stream Objects[^]
  Permalink  
v2

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

  Print Answers RSS
0 Mathew Soji 274
1 BillWoodruff 270
2 Afzaal Ahmad Zeeshan 244
3 Sergey Alexandrovich Kryukov 240
4 Raul Iloc 160
0 OriginalGriff 6,219
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,103
3 Manas Bhardwaj 4,549
4 Maciej Los 3,845


Advertise | Privacy | Mobile
Web01 | 2.8.1411019.1 | Last Updated 22 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100