summaryrefslogtreecommitdiff
path: root/swift/test/Ice/udp/Server.swift
blob: e2f72e0e55ec083a2bce8adfeec225ff1a568342 (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
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//

import Ice
import TestCommon

class Server: TestHelperI {
    public override func run(args: [String]) throws {
        var restArgs = args
        let properties = try createTestProperties(&restArgs)
        properties.setProperty(key: "Ice.Warn.Connections", value: "0")
        properties.setProperty(key: "Ice.UDP.RcvSize", value: "16384")

        let communicator = try initialize(properties)
        defer {
            communicator.destroy()
        }
        let num = restArgs.count == 4 ? Int32(restArgs[3]) : 1
        communicator.getProperties().setProperty(key: "ControlAdapter.Endpoints",
                                                 value: getTestEndpoint(num: num ?? 0, prot: "tcp"))
        let adapter = try communicator.createObjectAdapter("ControlAdapter")
        try adapter.add(servant: TestIntfDisp(TestIntfI()), id: Ice.stringToIdentity("control"))
        try adapter.activate()
        serverReady()
        if num == 0 {
            communicator.getProperties().setProperty(key: "TestAdapter.Endpoints",
                                                     value: getTestEndpoint(num: 0, prot: "udp"))
            let adapter2 = try communicator.createObjectAdapter("TestAdapter")
            try adapter2.add(servant: TestIntfDisp(TestIntfI()), id: Ice.stringToIdentity("test"))
            try adapter2.activate()
        }

        var endpoint: String = ""
        //
        // Use loopback to prevent other machines to answer.
        //
        if properties.getProperty("Ice.IPv6") == "1" {
            endpoint += "udp -h \"ff15::1:1\" --interface \"::1\""
        } else {
            endpoint += "udp -h 239.255.1.1 --interface 127.0.0.1"
        }
        endpoint += " -p "
        endpoint += "\(getTestPort(properties: properties, num: 10))"
        communicator.getProperties().setProperty(key: "McastTestAdapter.Endpoints", value: endpoint)
        let mcastAdapter = try communicator.createObjectAdapter("McastTestAdapter")
        try mcastAdapter.add(servant: TestIntfDisp(TestIntfI()), id: Ice.stringToIdentity("test"))
        try mcastAdapter.activate()
        communicator.waitForShutdown()
    }
}