【发布时间】:2013-10-14 11:21:39
【问题描述】:
我正在寻找的只是一个简单的 TCPClient/Listener(“hello world”)示例。我是新手,Microsoft TCPClient/Listener 类示例不是我想要的。我正在寻找的只是让 TCPClient 发送消息“Hello world”,让 TCPListener 获取消息并返回消息“我收到你的 hello world 消息”?
一点帮助会很棒。我所拥有的只是发送“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)
【问题讨论】:
-
是的..发送应该没问题;假设没有实际的协议(大部分时间都有)。然而,接收总是比人们想象的要复杂。你可能对我在 EE 的article 感兴趣。
-
那个链接真的很有帮助!!谢谢!!
标签: vb.net client-server tcpclient tcplistener