I'm trying to read a response from a third-party, socket based API (Fishbowl) and when I try to read what is returned my project freezes. I'm able to connect, send a request, and close the connection without error.
To test my code I created my own basic server app and my client app works as expected with it. It just doesn't work when I try that same client project against the third-party API.
Any ideas what could be causing this?
Here is my code:
Imports System.Net.Sockets
Imports System.Text
Public Class Form1
Dim VarSocketServer As New TcpClient
Dim VarNetworkStream As NetworkStream
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
VarSocketServer.Connect("127.0.0.1", 28192)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim VarNetworkStream As NetworkStream = VarSocketServer.GetStream()
' Send a msessage/request to the server. This doesn't return errors and appears to work.
Dim VarClientRequest As String = "{My request is sent in JSON and includes credentials and key}"
Dim VarSendByte As [Byte]() = System.Text.Encoding.ASCII.GetBytes(VarClientRequest)
VarNetworkStream.Write(VarSendByte, 0, VarSendByte.Length)
VarNetworkStream.Flush()
' Read the response from the server. This freezes at "VarNetworkStream.Read"
Dim VarInStream(10024) As Byte
Dim VarBytesRead = VarNetworkStream.Read(VarInStream, 0, VarInStream.Length)
Dim VarDataFromServer As String = System.Text.Encoding.ASCII.GetString(VarInStream)
VarNetworkStream.Flush()
Console.WriteLine(">> Data from server: " + VarDataFromServer)
Console.ReadLine()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
VarSocketServer.Close()
Me.Close()
End Sub
End Class