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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19232410/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 17:12:38  来源:igfitidea点击:

Simple TCPClient/Listener ("hello world") example

vb.netclient-servertcpclienttcplistener

提问by Benjamin Jones

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"?

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

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

一点帮助会很棒。我所拥有的只是发送“Hello World”的 TCPClient。这行得通吗?

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)

采纳答案by Synaps3

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

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

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

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