VB.NET中与TCPClient的TCP客户端/服务器通信 [英] TCP Client/Server Communications with TCPClient in VB.NET
本文介绍了VB.NET中与TCPClient的TCP客户端/服务器通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在没有TcpListener的情况下在TCPClient中接收消息?我不希望我的聊天客户端要求端口转发,而且,TcpListener将错误消息弄乱了主机,提示该端口上已经存在一个侦听器.
How do I Receive messages in my TCPClient without a TcpListener? I don''t want my chat client to require port forwarding, Also, the TcpListener messes up the host with a error message saying there is already a listener on that port.
How do I accomplish this?
推荐答案
以下内容在c#中-但它变得非常简单.
C#中的TCP客户端服务器简介 [ ThreadPool [从辅助线程调用UI的另一种方法 [ ^ ].
如果不使用线程,则客户端在轮询服务器时似乎会挂起.另一种选择是使用异步io进行轮询-但这通常被认为更难以正确实现-祝您好运:)
更新
希望本文将指导您创建令人满意的解决方案:
使用异步TCP套接字的聊天应用程序 [
The following is in c# - but it''s about as simple as it gets.
Introduction to TCP client server in C#[^]
Without a TCPListener you have to actively poll the server for data, on its own, the TCPClient does not listen for incomming requests.
Use something like ThreadPool[^] to poll data from the server asynchronously, and remember to synchronize access from the worker thread with the UI thread - Another way to Invoke UI from a Worker Thread[^].
If you don''t use threads your client will appear to hang while polling the server. Another option is to poll using asynch io - but that''s usually considered harder to implement correctly - good luck :)
Update
Hopefully this article will guide you towards creating a satisfying solution:
A Chat Application Using Asynchronous TCP Sockets[^]
Regards
Espen Harlinn
这篇关于VB.NET中与TCPClient的TCP客户端/服务器通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文