-1

The input value is posted twice as I use myHub.Invoke(Of String)("Chatter", Input) two places after declaring and in else statement.

I don't know whether I can replace the .continuewith block in the below code.

Sub Main()
    Dim connection = New HubConnection("http://localhost:8080")

    Dim myHub = connection.CreateHubProxy("myHub")

    connection.Start().Wait()
    Console.ForegroundColor = ConsoleColor.Yellow
    Dim Input As String = Console.ReadLine
    myHub.Invoke(Of String)("Chatter", Input) _
    .ContinueWith(
        Sub(task)
            If task.IsFaulted Then
                Console.WriteLine("Could not Invoke the server method Chatter: {0}", _
                                  task.Exception.GetBaseException())
            Else
                myHub.Invoke(Of String)("Chatter", Input)
                Console.WriteLine("Enter a value to send to the Client.  Enter 'Exit' to quit")
                Input = Console.ReadLine()
                Console.WriteLine("Success calling chatter method")

            End If
        End Sub)

    myHub.On(Of String)("addMessage", _
        Sub(param)
                Console.WriteLine("Client receiving value from server: {0}", param.ToString())
            End Sub)
    Console.ReadLine()
End Sub

After replacing continuewith block the client is not receiving the value from server.

 Sub Main()
Dim connection = New HubConnection("http://localhost:8080")

Dim myHub = connection.CreateHubProxy("myHub")
connection.Start().Wait()
Console.ForegroundColor = ConsoleColor.Yellow
Dim Input As String = Console.ReadLine
myHub.Invoke(Of String)("Chatter", Input) _
.ContinueWith(
Sub(task)
If task.IsFaulted Then
Console.WriteLine("Could not Invoke the server method Chatter: {0}", _
task.Exception.GetBaseException())
Else
myHub.Invoke(Of String)("Chatter", Input)
Console.WriteLine("Enter a value to send to the Client. Enter 'Exit' to quit")
Input = Console.ReadLine()
Console.WriteLine("Success calling chatter method")

End If
End Sub)

myHub.On(Of String)("addMessage", _
Sub(param)
Console.WriteLine("Client receiving value from server: {0}", param.ToString())
End Sub)
Console.ReadLine()
End Sub
halfer
  • 19,824
  • 17
  • 99
  • 186
Aarthi
  • 7
  • 1
  • 9
  • I want to change your title with a more useful one, but it is hard to work out what the actual question is here. What doesn't the first code block do that you want to correct in the second version? – halfer Oct 07 '16 at 18:22
  • hi i'm sending the user input value using " Dim Input As String = Console.ReadLine myHub.Invoke(Of String)("Chatter", Input) _ " from client to server after i sent more than two user input values the output window exits i need to implement a loop after this invoke statement but i'm not doing it right could you please help me and i'm not sure what happens sub(task) if else loop – Aarthi Oct 10 '16 at 10:23
  • This is your original question, please work on improving this. Put clarifications in the question rather than in the comments. Do not keep on re-asking the same thing, thanks. – halfer Oct 11 '16 at 08:23
  • i have done that but still i'm not receiving any response i have been waiting for long time and still struck in .continuewith statement – Aarthi Oct 11 '16 at 09:00
  • please find the comments for your reference i have been doing that but after finding no help i started posting again – Aarthi Oct 11 '16 at 09:03
  • Thanks for your support Chris you gave the kick start Thank you soo much – Aarthi Oct 11 '16 at 12:32
  • Hii Halfer please find the SOLUTION above its working fine – Aarthi Oct 12 '16 at 13:22

1 Answers1

0

(Posted on behalf of the OP).

Solution:

Sub Main()
    Dim connection = New HubConnection("http://localhost:8080")

    Dim myHub = connection.CreateHubProxy("myHub")

    connection.Start().Wait()
    Console.ForegroundColor = ConsoleColor.Yellow
    myHub.On(Of String)("addMessage", _
     Sub(param)
          'If param.Length > 0 < 2 Then
          Console.WriteLine("Client receiving value from server: {0}", param.ToString())
          ' End If
      End Sub)
    Dim input As String = Console.ReadLine()
    myHub.Invoke(Of String)("chatter", input)
    While input <> "exit"
        input = Console.ReadLine()
        myHub.Invoke(Of String)("chatter", input)


    End While

    myHub.On(Of String)("addMessage", _
        Sub(param)
            Console.WriteLine("Client receiving value from server: {0}", param.ToString())
        End Sub)
    Console.ReadLine()
End Sub
halfer
  • 19,824
  • 17
  • 99
  • 186
  • it would have been if you could change is -1 duplicate instead of posting this answer – Aarthi Oct 13 '16 at 12:46
  • @Aarthi: "OP" is an abbreviation for "original poster", that's you. I posted this because we ask that answers should be posted here, and not as an edit to the question above. – halfer Oct 13 '16 at 13:00
  • Thanks for the clarification – Aarthi Oct 14 '16 at 07:01