简单的TCP客户端/监听器("hello world")示例

10
我需要的只是一个简单的TCPClient/Listener(“hello world”)示例。我是个新手,微软的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)

7
是的,如果没有实际协议(大多数情况下都有),那么发送应该是可以的。然而,接收总是比人们想象的要复杂。你可能会对我在EE上的这篇文章感兴趣。 - Idle_Mind
那个链接真的很有帮助!谢谢! - Benjamin Jones
1个回答

4

10
请添加一些代码,如果您分享的网站变得过时,那么您的答案也会变得过时。 - Cary Bondoc
...因为它已经部分发生了。 - geer

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接