10

All I'm looking for is a simple TCPClient/Listener ("hello world") example. I'm a newbie and Microsoft TCPClient/Listener class examples are not what I am looking for. All I am looking is for the TCPClient to send a message "Hello world" and for a TCPListener to get the message and to send a message back "I got your hello world message"?

A little help would be great. All I have is the TCPClient sending out "Hello World". Would this work?

Dim port As Int32 = 13000
        Dim client As New TcpClient("192.168.0.XXX", port)
        ' Translate the passed message into ASCII and store it as a Byte array. 
        Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes("Hello World")

    ' Get a client stream for reading and writing. 
    '  Stream stream = client.GetStream(); 
    Dim stream As NetworkStream = client.GetStream()

    ' Send the message to the connected TcpServer. 
    stream.Write(data, 0, data.Length)
Cœur
  • 37,241
  • 25
  • 195
  • 267
Benjamin Jones
  • 987
  • 4
  • 22
  • 50
  • 7
    Yes..that should be fine for sending; assuming there is no actual protocol (most of the time there is). Receiving, however, is always more complicated than people think. You may be interested in my [article](http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/A_11178-A-Peer-To-Peer-LAN-Chat-Application-in-Visual-Basic-Net-using-TcpClient-and-TcpListener.html) over at EE. – Idle_Mind Oct 07 '13 at 20:46
  • That link really helped!! Thanks!! – Benjamin Jones Oct 09 '13 at 02:05

1 Answers1

4

These two tutorials should show you how to do it with the bare minimum. The first one is more aimed at what you want I think.

Try this: http://www.nullskull.com/articles/20020323.asp

Or this: http://www.codeproject.com/Articles/38914/A-TCP-IP-Chat-Program

Synaps3
  • 1,597
  • 2
  • 15
  • 23