简单的TCPClient / Listener(“hello world”)示例

时间:2013-10-07 18:54:40

标签: vb.net client-server tcpclient tcplistener

我正在寻找的是一个简单的TCPClient / Listener(“hello world”)示例。我是新手,Microsoft TCPClient / Listener类示例不是我想要的。我正在寻找的是TCPClient发送消息“Hello world”和TCPListener获取消息并发回消息“我收到了你的hello world消息”?

一点帮助会很棒。我只有TCPClient发出“Hello World”。这会有用吗?

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)

1 个答案:

答案 0 :(得分:5)

这两个教程应该向您展示如何使用最低限度来完成它。第一个更瞄准你想要的东西。

试试这个:http://www.nullskull.com/articles/20020323.asp

或者:http://www.codeproject.com/Articles/38914/A-TCP-IP-Chat-Program