|
|
1.1 root 1: /****************************************************************************
2:
3: Microsoft RPC Version 1.0 Alpha
4: October 1991
5: Adder1 Example
6:
7: FILE: adder1\client.c
8: USAGE: client <servername>
9: where <servername> is the name of the server running the
10: server side of the distributed application
11: PURPOSE: Client side of RPC distributed application adder1
12: FUNCTIONS: main() - calls remote procedure AdderProc1
13: COMMENTS:
14: This version of the distributed application that adds two
15: short integers features a client that manages its connection
16: to the server. It uses the binding handle hRpcAdder1.
17:
18: ****************************************************************************/
19: #include <stdio.h> // printf
20: #include <string.h> // strlen
21: #include <stdlib.h> // exit
22:
23: #include <rpc.h> // RPC API functions, types
24: #include "adder1.h" // RPC data for this interface
25:
26: #define MAXPATH 300 // arbitrary large size for server, pipe path
27:
28: void main(int argc, char **argv)
29: {
30: RPC_STATUS status; // returned by RPC API function
31: char * pszRpcPort = "adder1";
32: char szServerPath[MAXPATH]; // complete path
33: short sAdderResult;
34:
35:
36: /* Select named pipes as the transport type and provide the */
37: /* path to the server and named pipe that is used for RPC. */
38: /* The client specifies the local pipe name in the form: */
39: /* \device\namedpipe\pipename */
40: /* The client specifies the remote pipe name in the form: */
41: /* \device\lanmanredirector\servername\pipe\pipename */
42: /* In this example, the pipename is "adder1" */
43:
44: if (argc == 2) {
45: strcpy(szServerPath, "\\device\\lanmanredirector\\");
46: strcat(szServerPath, argv[1]); // servername
47: strcat(szServerPath, "\\pipe\\");
48: strcat(szServerPath, pszRpcPort);
49: }
50: else {
51: strcpy(szServerPath, "\\device\\namedpipe\\");
52: strcat(szServerPath, pszRpcPort);
53: }
54:
55: adder1_ProtocolStack.TransportType = RPC_TRANSPORT_NAMEPIPE;
56:
57: adder1_ProtocolStack.TransportInfo = szServerPath;
58: adder1_ProtocolStack.TransportInfoLength = \
59: strlen(szServerPath) + 1; // add 1 for terminating null
60:
61: /* Call the Microsoft RPC V1.0 Alpha API function that allows */
62: /* the client to establish a connection with the server. */
63: /* NOTE: This function will probably be replaced in future */
64: /* releases by the standard DCE RPC function. */
65:
66: status = RpcBindToInterface(&adder1_ProtocolStack,
67: 0L,
68: &hrpcAdder1);
69: if (status) {
70: printf("RpcBindToInterface returned 0x%x\n", status);
71: printf("%s length = %d\n", adder1_ProtocolStack.TransportInfo,
72: adder1_ProtocolStack.TransportInfoLength);
73: exit(2);
74: }
75:
76: sAdderResult = AdderProc1(1, 2); // call the remote procedure
77: printf("result from remote procedure = %d\n", sAdderResult);
78:
79: status = RpcUnbind(hrpcAdder1); // remote calls complete; unbind
80: if (status) {
81: printf("RpcUnbind returned 0x%x\n", status);
82: exit(2);
83: }
84: exit(0);
85: } /* end main() */
86: /* end adder1\client.c */
87:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.