Home > other >  ProudNet using method # 4: the RMI
ProudNet using method # 4: the RMI

Time:09-23

ProudNet is to study game software development of the service side & amp; The network engine,

Using SendUserMessage send 2 hexadecimal data, at the receiving end OnReceiveUserMessage exist problems of receiving data manually,
To use ProudNet RMI functions it will become very convenient, RMI can remote call function, through the specific function of a computer program for the remote control,
Like to develop a computer program, the client sent to the server server after two values will sum the results sent to the client's way,
Define these functions, the following code to define the RMI functions,
1. Global CalcC2S
2. {
3. RequestAdd (int a [in], [in] int b);
4.}
5.
6. Global CalcS2C
7. {
8. ReponseAdd (int [in] the sum);
9.}


Line 3, 8 lines represent information format,
The following code is the client sends information to the server process,
1. [c + +]
2.
3. CalcC2SProxy. RequestAdd (HostID_Server RmiContext: : ReliableSend, 3, 4);
4.
5.
6.
7. (c #)
8. CalcC2SProxy. RequestAdd (HostID. Server, RmiContext ReliableSend, 3, 4);


To CalcC2S CalcS2C do in detail in the next chapter, first of all, RequestAdd sent to the "who", is the first factor to join the HostID. The Server is sent to the Server, and second, "how to send", introduced before RmiContex, then other factors is the RMI defined before,
Above process for sending information,
The following code to the server process information received from the client process,
1. [c + +]
2. CalcC2SStub. RequestAdd_Function=[...]. PARAM_CalcC2SStub_RequestAdd {//[1]
3. Int sum=a + b;//[2]
4. CalcS2CProxy. ResponseAdd (remote, RmiContext: : ReliableSend, sum);//[3]
5.};
6.
7.
8. (c #)
9. CalcC2SStub. RequestAdd=(remote rmiContext, a, b) {//[1]
10. Int sum=a + b;//[2]
11. CalcS2CProxy. ResponseAdd (remote, RmiContext ReliableSend, sum);//[3]
12.};


[1] : the client sends information from the remote call RequestAdd runtime, adding Lambda expressions, [...]. Contains a Lambda expressions,
[2] : add two values,
[3] : server Remote call the client function, the server sends to the client the calculation results of two values, Remote represents the receiving, tapper HostID,
The following code to the client processing received information,
1. [c + +]
2. CalcS2CStub. ResponseAdd_Function=[...]. PARAM_CalcS2CStub_ResponseAdd {
3. Print (sum);
4.};
5.
6.
7. (c #)
8. CalcS2CStub. ResponseAdd=(remote rmiContext, sum) {
9. The print (sum);
10.};


The above for all process, such as the need to add more kinds of initial information, you can add definition to the RMI function part, if want to change the formatting information need to modify the RMI the parameters of the function definition, the game development process to tens of thousands of kinds of information processing will become easy,
Will define the information added to the RMI. Pid file, and then added to the Calc. Pid file,
Then using PIDL complier generating code to send and receive information, detailed reference links guide.nettention.com/cpp_zh
(reference: under Linux ProudNet environment also use PIDL compiler running)
PIDL complier generate transmitting and receiving rules, mail proxy rules, rules of receiving a stub. Generate PIDL complier language c + +, c #, Java and Unreal Script).
CalcS2CProxy, and introduces the CalcS2CStub:
PIDL file defined CalcC2S CalcS2C is RMI function set, PIDL compiler compiled to generate the following class,
CalcC2S. Proxy
CalcC2S. Stub
CalcS2C. Proxy
CalcS2C. Stub


Represent the
CalcC2S. Proxy: the client - & gt; A letter from the server class, namely proxy
CalcC2S. Stub: client - & gt; Server receiving classes, namely a stub
CalcS2C. Proxy: the service side - & gt; The client's mail classes, namely the proxy
CalcS2C. Stub: server - & gt; The client receiving classes, namely a stub


Client only consider CalcC2S. Proxy and CalcS2C. Stub, considering all the other service end,
PIDL compiler generated class attached to NetClient and NetServer, additional ways as follows,
1. Create a class instance,
2. Create an instance of using AttachProxy, additional AttachStub function,
The following is attached to the client code,
1. [c + +]
2. CalcC2S: : Proxy CalcC2SProxy;
3. C - & gt; AttachProxy (& amp; CalcC2SProxy);
4. CalcS2C: : StubFunctional CalcS2CStub;
5. C - & gt; AttachStub (& amp; CalcS2CStub);
6.
7.
8. (c #)
9. CalcC2S. Proxy CalcC2SProxy;
10. C.a. ttachProxy (CalcC2SProxy);
11. CalcS2C. StubFunctional CalcS2CStub;
12. C.a. ttachStub (CalcS2CStub);



Landing function is added to connect to the server,
First of all, for landing PIDL file statement RMI functions, and then send login request to the client, the server processing after reply, shows the result after the client accept, the following code
1. Global CalcC2S
2. {
3. RequestLogin (string id [in], [in] string password).
4.}
5.
6. Global CalcS2C
7. {
8. ResponseLogin ([in] bool success);
9.}
10.
11.
12. [c + +]
13. CalcC2SProxy. RequestLogin (HostID_Server RmiContext: : SecureReliableSend, "John", "Marine");
14.
15. CalcC2SStub. RequestLogin_Function=[...]. PARAM_CalcC2SStub_RequestLogin {
16. The bool s=false;
17. The if (id==... & & Password==... )
18. {
19. S=true;
20.}
21.
22. CalcS2CProxy. ResponseLogin (remote, RmiContext: : ReliableSend, s);
23.};
24.
25. CalcS2CStub. ResponseLogin_Function=[...]. PARAM_CalcS2CStub_ResponseLogin {
26. The print (success);
27.};
28.
29.
30. (c #)
31. CalcC2SProxy. RequestLogin (HostID. Server, RmiContext SecureReliableSend, "John", "Marine");
32.
33. CalcC2SStub. RequestLogin=(remote rmiContext, id, password)=& gt; {
34. The bool s=false;
35. The if (id==... & & Password==... )
36. {
37. S=true;
38.}
39.
40. CalcS2CProxy. ResponseLogin (remote, RmiContext ReliableSend, s);
41.};
42.
43. CalcS2CStub. ResponseLogin=(remote rmiContext, success) {
44. The print (success);
45.};


Line 13 SecureReliableSend representatives have encryption to send, in order to prevent hackers and create a user name and password,

Conclusion:
1. The PIDL file defines the RMI function
2. Compile and build configuration,
3. The generated Proxy, Stub attached to NetClient and NetServer,
4. Call the generated Proxy function, can send information,
5. Attach the generated Stub function, can call this function,
nullnullnullnullnullnullnullnullnullnullnullnull
  • Related