summaryrefslogtreecommitdiff
path: root/objective-c/README.md
blob: b2bf7348a1d1fb4ad89ac1295497203d09356127 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Ice for Objective-C

[Getting started] | [Examples] | [Documentation] | [Building from source]

The [Ice framework] provides everything you need to build networked applications, including RPC, pub/sub, server deployment, and more.

Ice for Objective-C is the Objective-C implementation of the Ice framework.

## Sample Code

```slice
// Slice definitions (Hello.ice)

module Demo
{
    interface Hello
    {
        void sayHello();
    }
}
```

```objective-c
// Client application (Client.m)
#import <objc/Ice.h>
#import <Hello.h>

int
main(int argc, char* argv[])
{
    int status = 0;
    @autoreleasepool
    {
        id<ICECommunicator> communicator = nil;
        @try
        {
            communicator = [ICEUtil createCommunicator:&argc argv:argv];
            if(argc > 1)
            {
                NSLog(@"%s: too many arguments", argv[0]);
                return 1;
            }
            id<DemoHelloPrx> hello = [DemoHelloPrx uncheckedCast:
                [communicator stringToProxy:@"hello:default -p 10000"]];
            [hello sayHello];
        }
        @catch(ICELocalException* ex)
        {
            NSLog(@"%@", ex);
            status = 1;
        }

        [communicator destroy];
    }
    return status;
}
```

```objective-c
// Server application (Server.m)
#import <objc/Ice.h>
#import <HelloI.h>

int
main(int argc, char* argv[])
{
    int status = 0;
    @autoreleasepool
    {
        id<ICECommunicator> communicator = nil;
        @try
        {
            communicator = [ICEUtil createCommunicator:&argc argv:argv];

            id<ICEObjectAdapter> adapter = [communicator
                createObjectAdapterWithEndpoints: @"Hello"
                endpoints:@"default -p 10000"];
            [adapter add:[HelloI hello] identity:[ICEUtil stringToIdentity:@"hello"]];
            [adapter activate];
            [communicator waitForShutdown];
        }
        @catch(ICELocalException* ex)
        {
            NSLog(@"%@", ex);
            status = 1;
        }
        [communicator destroy];
    }
    return status;
}
```

```objective-c
// Printer declaration (Printer.h)
#import <Hello.h>

@interface Printer : DemoHello<DemoHello>
@end
```

```objective-c
// Printer implementation (Printer.m)
#import <Printer.h>

#include <stdio.h>

@implementation Printer
-(void) sayHello:(ICECurrent*)current
{
    printf("Hello World!\n");
    fflush(stdout);
}
@end
```

[Getting started]: https://doc.zeroc.com/ice/3.7/hello-world-application/writing-an-ice-application-with-objective-c
[Examples]: https://github.com/zeroc-ice/ice-demos/tree/3.7/objective-c
[Documentation]: https://doc.zeroc.com/ice/3.7
[Building from source]: https://github.com/zeroc-ice/ice/blob/3.7/objective-c/BUILDING.md
[Ice framework]: https://github.com/zeroc-ice/ice