A remote object invocation method

Source: Internet
Author: User
Tags session id stub
1. Useful After the completion, I used him to write a few examples. 1. X_corba_helle_world.exe, run the bin directory Hello_world_server.bat, or run X_corba_server_user_dll.exe is to start the service program, directly double-click is the client program, can see the effect. 2. X_corba_transfile.exe command Line input –help can see the Help file, or directly see the source code to know how to use, transmission file is not very ideal, a 1.8G file requires nearly 5 minutes. Running X_corba_server_user_dll.exe can also run service-side process 3. X_corba_server_user_dll, x_corba can compile the server-side code into a DLL and invoke it in an EXE. This feature extends the functionality of the service program. 4. In order to adequately display the concept of distributed systems, the last example I wrote a chat system consists of several executable programs.    A.  x_corba_char_client.exe  chat client. This is a console program for simplicity.        there is a point. I produced a function of the time there is a mistake, the chat wrong to write char, the same below! B. x_corba_char_config_server.exe server that is responsible for the configuration of the service. C. x_corba_char_room_alloc.exe Chat Room allocation server, D. x_corba_char_server_register.exe, user registration server, Information used to register online users. In which chat room the user is in, the session ID in the chat room. E. x_corba_char_msg_route.exe, a client chat record in a different chat room. In this way, users in different two chat rooms can chat. This is transparent to the user. F. x_corba_char_server_room.exe, chat room.         Description: 1, the commencement of the program has successively started Config_server,room_alloc,register_server,msg_route,room_server, And then the client can connect! After running, it countsCan be chat, just not a large test, in fact, I only have two computer operators run. A brief description of the functions of each program, Config_server, mainly save the configuration of each program, the main configuration is the address of other programs, when other programs start, you have to tell Config _server its address, all, Config_server must run first. And because Config_server interact with other programs less frequently throughout the system, all I think is that the entire system simply runs a Config_ The server process is OK. Room_alloc is the chat room allocation process, the allocation base starting from 1000, to an address allocation of an ID such as 1001,1002,room_server startup request Room_alloc get room_id, it has all the chat room address, and other Exchange procedures have msg_route described below. Register_server, which records all user login, and other information, including chat user's friend, user's room_id, and room_id session_id, and when the user quits, tries to notify all its chat friend . Msg_route, which is used to route two client messages in different chat rooms, it needs to get a room_id address, or a communication object, through Room_alloc. The real system should have a Msg_route group to perform a large number of frequent user message forwarding. Room_server is used to receive users, and the information they send over, to find that chat is no longer the chat room, will notify Msg_route forward their chat information. This is the whole process. It may be a bit complicated or it may not be complicated. No major tests have been done. To emphasize that I am not going to do this chat system, but to apply X_corba. Run the system, as long as you run the bat file on it, BAT file and serial number!   2, whether it is easy to useA. To introduce, like CORBA, this also has an IDL conversion tool, called Xcorba_idl.exe, syntax is similar but simpler. Accept the file suffix is a xidl file Xcorba_idl.exe! built-in data types:Void,bool8,char8,uint8,int16,uint16,int32,uint32,float32,double64, Bool8seq,char8seq,uint8seq,int16seq, Uint16seq,int32seq,uint32seq,float32seq,double64seq, the front of a look to know that the back of the suffix is seq is for the serialization of the type. In addition to the data type above, you can customize the data type. By using keywords: struct, class, interface.This 3 function is slightly different. Struct can only define the structure of a common part and will not generate client and server-side code. Interface defines interfaces, can have member variables, can have member functions, cannot inherit, class in addition to the function of interface, but also can inherit, interface and class-defined new types, or you can serialize custom data types. You can refer to the example above. includeUsed to contain other xidl files, syntax such as #include "Test.xidl" namespace, functions and syntax with C + + same Other:
"{} ();: #.,//
* */& *
and C + + same There are examples in the example.    b. Introduction and use of production documents        use methods you can enter Xcorba_idl.exe -h    view Help, Very simple.        generated files by default, there will be Comm, client_stub, Server_skel folders if you want to write a client-side program that contains only Client_ In the stub, if you want to write the server-side program, include Comm, and Server_skel files. There are several methods        client-side calls to the clients:        1, first set up XCORBA operating environment;               xcorba_environment __orb_comm_init;                 x_corba_initialize ();               if (!__orb_comm_init.startup ())               {                      return error;              }               2 to establish a service-side connection;            xcorba_client __client;                  if (!__client.orb_init (IP, port)                {                      return error;              }          3, call remote method:     A . Client-side calls, such as test_stub, with a function int print ();               Calling 1:test_stub __test;      //1                              __test.bind (__client);   //2                              __test.print ();         //3         This call I call it a simple method call. It's not like that soap. Call procedure: There is a collection of corresponding Test_skel objects on the server side, or an object pool, which, when received by the client side of __test.print (), will find an empty object in the pool (the process is not to traverse the pool to find, all the basic time consuming), Then call the method of the server, and return to the corresponding pool immediately after returning the object. At this point, the client receives the int value of returns. This simple method of invocation is the basic method. Of course, there are other functions, and even member variables, in addition to the print function, can also work very well.                       calls 2:test_stub __test (__client);      //1                              __test.print ();                               //2                you can see the merging of steps 1 and 2 in call 1, where is the difference, which I called in the example X_corba_transfile.exe, the difference being that, within the entire __test life domain, Corresponds to a test_skel on the server side, the method I called him hold call, I really don't know how to call it, this method requires more secure improvements to specific situations.                 Call 3: Asynchronous invocation, when calling Xcorba_idl.exe–c, A method that produces an asynchronous invocation. In fact, there will be two methods of production for one method, one is the method called, the other is the asynchronous response, and if the calling method has an answer, all functions that return void will not produce the asynchronous invocation method.        functions such as: UInt32 print1 (UInt32    a);        will produce:        public:                             void Print1_asyn (UInt32 a);        private:                             void On_print1_uint32 (const char8* _rev,uint32 _size);   above is the call method in 3, detailed can look at the production stub file of the CPP file differences. And look at some of the examples presented above.        B.Server calls        1, first set up the operating environment of Xcorba;               xcorba_environment __orb_comm_init;                  if (!__orb_comm_ Init.startup ())               {                      return Error              }         2, call X_corba_initialize ();     3, set up some service-side objects. For example, Test_skel          needs to manipulate a global  config object. __config.          So you can do that. Modify generated Test_skel add Config member variable                Test_skel  __test (__config);               if (! X_corba_bind_skel ("Namespace::test", &__test))                {                      break;              } namespace is the object in the name space, if it again!               through this method, you can interact outside of the pool's object pool, Another way to interact with me is to use the Singten mode.               there must be a better way to do it.           4, set up the service object. Xcorba_server        __orbserver;                 if (!__orbserver.orb_init ( IP, Port)               {                 &NBsp;    return error;              }                 __orbserver.orb_run (false); False is non-blocking, true is blocking               OK, By this time the service was established. Call __orbserver.stop () end service   3. Can you use
Hope to be able to use. The whole thing was built on a person's mind, and I don't know, in some unforeseen circumstances, if you can work well. If you've done a network-related application, you'll find it difficult to work as you expect, and it's always going to be more than you'd expect. That's the way the program is. Although the beginning is planned, but later are very confusing.    If the program is like eating a hamburger, after eating one, the following thing is to consider eating the next one, or take a break. It's more comfortable to do a procedure than to sleep. If you see this document friend, interested, you can use, if found anything wrong, or wrong place can notify me. I hope this thing will work. This is something I have done that I am more satisfied with. 4. OtherIndeed, this is a lot worse than CORBA, CORBA's idea is to make the network programming simpler, more simple to do the distributed system, in fact, the idea of OO to do the application of the network is very simple, as you see the example. hehe.        In other words, the call in the example is not very good, and there is a lot of room for improvement. Writing programs is a product of technological development, but we are working in a more primitive way. Hope to do better.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.