summaryrefslogtreecommitdiff
path: root/vb/demo/Ice/async/Client.vb
blob: c30b1a1b5eb6df31909d072fd11406929bf965b3 (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
' **********************************************************************
'
' Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved.
'
' This copy of Ice is licensed to you under the terms described in the
' ICE_LICENSE file included in this distribution.
'
' **********************************************************************

Imports System
Imports Demo

Module AsyncC

    Class Client
        Inherits Ice.Application

        Public Sub success()
        End Sub

        Public Sub exception(ByVal ex As Ice.Exception)
            If TypeOf ex Is RequestCanceledException Then
                Console.Error.WriteLine("RequestCanceledException")
            Else
                Console.Error.WriteLine("sayHello AMI call failed:")
                Console.Error.WriteLine(ex)
            End If
        End Sub

        Private Sub menu()
            Console.WriteLine("usage:")
            Console.WriteLine("i: send immediate greeting")
            Console.WriteLine("d: send delayed greeting")
            Console.WriteLine("s: shutdown server")
            Console.WriteLine("x: exit")
            Console.WriteLine("?: help")
        End Sub

        Public Overloads Overrides Function run(ByVal args() As String) As Integer
            If args.Length > 0 Then
                Console.Error.WriteLine(appName() & ": too many arguments")
                Return 1
            End If

            Dim hello As HelloPrx = HelloPrxHelper.checkedCast(communicator().propertyToProxy("Hello.Proxy"))
            If hello Is Nothing Then
                Console.Error.WriteLine("invalid proxy")
                Return 1
            End If

            menu()

            Dim line As String = Nothing
            Do
                Try
                    Console.Out.Write("==> ")
                    Console.Out.Flush()
                    line = Console.In.ReadLine()
                    If line Is Nothing Then
                        Exit Do
                    End If
                    If line.Equals("i") Then
                        hello.sayHello(0)
                    ElseIf line.Equals("d") Then
                        hello.begin_sayHello(5000).whenCompleted(AddressOf success, AddressOf exception)
                    ElseIf line.Equals("s") Then
                        hello.shutdown()
                    ElseIf line.Equals("x") Then
                        ' Nothing to do
                    ElseIf line.Equals("?") Then
                        menu()
                    Else
                        Console.WriteLine("unknown command `" & line & "'")
                        menu()
                    End If
                Catch ex As System.Exception
                    Console.Error.WriteLine(ex)
                End Try
            Loop While Not line.Equals("x")

            Return 0
        End Function
    End Class

    Public Sub Main(ByVal args() As String)
        Dim app As Client = New Client
        Dim status As Integer = app.Main(args, "config.client")
        System.Environment.Exit(status)
    End Sub
End Module