Click here to Skip to main content
15,883,810 members

TCP/IP Winsock Communications work in Hyperterminal but I cannot get them to work in VB.Net.

prcunningham asked:

Open original thread
I have a device that I can connect to using HyperTerminal and send strings and receive back the data I need but I cannot get it to work in VB.Net. In VB I can connect and send a string but the data a get back is garbage. I have tried every possible way to write the code but below is the way I have it currently written.

VB
Dim tcpClient As New System.Net.Sockets.TcpClient()
tcpClient.Connect(SERVER_ADDR, SERVER_PORT)
Using networkStream As NetworkStream = tcpClient.GetStream()
    If networkStream.CanWrite And networkStream.CanRead Then
        ' Do a simple write.
        Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("?LEAK")
        networkStream.Write(sendBytes, 0, sendBytes.Length)
        ' Read the NetworkStream into a byte buffer.
        Dim bytes(tcpClient.ReceiveBufferSize) As Byte
        networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
        ' Output the data received from the host to the console.
        Dim returndata As String = Encoding.ASCII.GetString(bytes)
        Console.WriteLine(("Host returned: " + returndata))
    Else
        If Not networkStream.CanRead Then
            Console.WriteLine("cannot not write data to this stream")
            tcpClient.Close()
        Else
            If Not networkStream.CanWrite Then
                Console.WriteLine("cannot read data from this stream")
                tcpClient.Close()
            End If
        End If
    End If
End Using
Console.ReadLine()


All I did to setup HyperTerminal was IP Address, Port Number and TCP/IP (Winsock). Any help would be greatly appreciated.
Tags: Visual Basic, TCP/IP

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900