收听TCP客户端

编程入门 行业动态 更新时间:2024-10-23 13:34:44
本文介绍了收听TCP客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个TCP客户端,我需要监听并发送响应。使用c#实现这一目标的最佳方法是什么? 我过去做过一些事情,但我是客户端,在这种情况下我需要成为服务器。我一直在寻找通过给定端口连接到客户端并监听/发送数据的方法......但没有结果...... 这是我的代码到目前为止....

private void ListeningThread() // 让我们在另一个线程中监听!! { int port = 12345 ; // 根据需要更改 this .listener = new TcpListener(IPAddress.Any,port); 尝试 { 此 .listener。开始(); } catch (例外e){MessageBox.Show( 无法绑定到端口 + port + - > + e.Message); 返回; } while ( true ) { Thread.Sleep( 30 ); } }

现在我需要在while cicle中接收数据并将其转换为字符串...

解决方案

我猜你在谈论TcpListener类 [ ^ ]。 也可参考 - 用C#编写的TCP / IP服务器 [ ^ ]。

I have a TCP client that I need to Listen and send responses. What’s the best way to achieve this with c#? I’ve done something in the past but I was the client, in this situation I need to be the server. I’ve been searching a way to connect to the client through a given port and listen/send data….but with no results…. Here's my code so far....

private void ListeningThread() // let's listen in another thread instead!! { int port = 12345; // change as required this.listener = new TcpListener(IPAddress.Any, port); try { this.listener.Start(); } catch (Exception e) { MessageBox.Show("couldn't bind to port " + port + " -> " + e.Message); return; } while (true) { Thread.Sleep(30); } }

Now I need, in the while cicle, to receive data and convert it to a string...

解决方案

I guess you are talking about TcpListener Class[^]. Also refer - A TCP/IP Server written in C#[^].

更多推荐

收听TCP客户端

本文发布于:2023-11-25 09:05:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629154.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:客户端   TCP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!