tcpclient 相关问题

.NET Framework类,为TCP网络服务提供客户端连接。


我如何收到对单个TCP/IP请求的多个回复? 我正在使用我通过TCP/IP连接进行通信的第三方设备。 根据供应商提供的手册,当我发送到运行命令时,该工具是启动的(

SIC_Marking_Tool_Command = command; lblCommandSent.Text = command; #region "Set SIC_Marking_Tool_URI" TcpClient PostMarkingRequestTcpClient = new TcpClient(); PostMarkingRequestTcpClient.Connect("192.168.50.221", 65535); #endregion // Get a client stream for reading and writing. NetworkStream stream = PostMarkingRequestTcpClient.GetStream(); // Translate the passed message into ASCII and store it as a Byte array. Byte[] PostMarkingRequestByteArray = System.Text.Encoding.ASCII.GetBytes("RUN\r\n"); // SIC_Marking_Tool_Command); // Send the message to the connected TcpServer. stream.Write(PostMarkingRequestByteArray, 0, PostMarkingRequestByteArray.Length); // Buffer to store the response bytes. Byte[] PostMarkingResponsed = new Byte[256]; // String to store the response ASCII representation. String responseData = String.Empty; // Read response bytes. Int32 PostMarkingResponsedBytes = stream.Read(PostMarkingResponsed, 0, PostMarkingResponsed.Length); rtbResponses.Text = string.Empty; rtbResponses.Text = Encoding.ASCII.GetString(PostMarkingResponsed, 0, PostMarkingResponsedBytes); int databytes = stream.Read(PostMarkingResponsed, 0, PostMarkingResponsed.Length); #region "wait for test results" if ((int)cbCommand.SelectedIndex == (int)enum_commands.enum_Run) { // Read response bytes. PostMarkingResponsedBytes = stream.Read(PostMarkingResponsed, 0, PostMarkingResponsed.Length); rtbResponses.Text = "\r\n " + rtbResponses.Text + Encoding.ASCII.GetString(PostMarkingResponsed, 0, PostMarkingResponsedBytes); } #endregion Here an the image of my simple POC client [![TCP IP Client Showing the response info received][1]][1] The tool manufacture communication protocol manual states that the following: [![The tool manufacture communication protocol manual states that the following][2]][2] [1]: https://i.sstatic.net/DK6WeP4E.png [2]: https://i.sstatic.net/3GsmE0Ml.png Please see the code below that demonstrates how I handled receiving the multiple response messages. I would be appreciative if anyone has recommendation on how to do things a better way. Would like to thank Marc. I read the linked articles that helped my grasp some of the basic things I was missing. Here's My code: #region "wait for test results" if ((int)cbCommand.SelectedIndex == (int)enum_commands.enum_Run) { string CMDResponse1 = string.Empty; int MarkingResponseBytes = 0; bool ACK_Received = false; //Acknowledge bool DC4_Received = false; //Device Control 4 bool ENQ_Received = false; //Enquiry Transmission bool EOT_Received = false; //End of Transmission bool NAK_Received = false; //Negative Acknowledge while (!NAK_Received && !ENQ_Received) { Byte[] MarkingResponse = new Byte[256]; MarkingResponseBytes = stream.Read(MarkingResponse, 0, MarkingResponse.Length); Thread.Sleep(500); var markresponse = Encoding.ASCII.GetString(MarkingResponse, 0, MarkingResponseBytes); #region "RUN OK response received" if (markresponse.Contains("RUN OK")) { ACK_Received = true; rtbResponses.Text = Encoding.ASCII.GetString(MarkingResponse, 0, MarkingResponseBytes); } #endregion #region "P response received" if (Encoding.ASCII.GetString(MarkingResponse, 0, MarkingResponseBytes).ToLower() == "p") { rtbResponses.Text = rtbResponses.Text + "\n" + Encoding.ASCII.GetString(MarkingResponse, 0, MarkingResponseBytes); } #endregion #region "EOT Repsonse Received" if (markresponse.Contains("\u0004")) { EOT_Received = true; rtbResponses.Text = rtbResponses.Text + "\n" + "End of Transmission (EOT) response received."; } #endregion #region "ENQ Repsonse Received" if (markresponse.Contains("\u0005")) { ENQ_Received = true; rtbResponses.Text = rtbResponses.Text + "\n" + "Enquiry Transmission (ENQ) response received."; } #endregion #region "DC4 Response Received" if (markresponse.Contains("\u0014")) { DC4_Received = true; rtbResponses.Text = rtbResponses.Text + "Device Control 4 (DC4) response received."; } #endregion #region "NAK Response Recieved" if (markresponse.Contains("\u0015")) { NAK_Received = true; rtbResponses.Text = rtbResponses.Text + "\nNegative Acknowledgement (NAK) response received." + "\nMarking out of bounds"; } #endregion } } #endregion #region "Read normal command response bytes" else { Byte[] CommandResponse = new Byte[256]; CommandResponseBytes = stream.Read(CommandResponse, 0, CommandResponse.Length); rtbResponses.Text = Encoding.ASCII.GetString(CommandResponse, 0, CommandResponseBytes); } #endregion

回答 0 投票 0


ggstreamer创建RTP流

我想使用GSTREAMER包装和流式传输H264视频帧。 UDP方法成功了,但是TCP方法不起作用。我的问题是什么? 这是RTP客户端程序。以下是CO ...

回答 1 投票 0

建立连接后客户端立即断开连接

输出 我被要求在 TCP 服务器/客户端情况下的先前项目中实现一个纸牌游戏(加载和保存无法按预期运行,但这不应影响连接)。 ...

回答 1 投票 0

C# TCP 在同一本地端口上监听并连接

我有一个 C# 控制台应用程序,我正在尝试实现 TCP 打孔。 我需要监听本地端口并同时(同时/异步)连接到 2 个不同的远程...

回答 2 投票 0

有没有办法用C#模拟SQL Server?

我想创建一个模拟的 SQL 服务器,给它一个日志文件来模拟。 我不想处理一个完整的 Sql 服务器,我必须在其中输入虚拟数据,但是一个简单的脚本(日志)猴子 u...

回答 1 投票 0

如何使用gstreamer从实时视频方法tcpclientsrc application/x-rtp-stream编码JPEG视频流录制到文件?

我使用 Gstreamer 处理实时摄像机视频流,并通过 tcpserversink、jpegenc、rtpjpegpay 和 rtpstreampay 发送。 我在开放广播工作室使用 Gstreamer 接收此工作:

回答 1 投票 0

证书吊销和 CRL 状态未知

我需要帮助来了解如何配置以及证书吊销在 Windows 中的实际工作原理。 我正在测试一种场景,其中我有一个自签名证书,该证书将是根 CA 的证书,

回答 0 投票 0

NS3套接字编程

#include“ns3/applications-module.h” #include“ns3/core-module.h” #include“ns3/csma-module.h” #include“ns3/internet-module.h” #include“ns3/网络模块.h” #include“ns3/socket.h” #包括<

回答 1 投票 0

C 语言 TCP/IP 编程

我明天有一场 TCP/IP 编程考试。以下是本文之前的问题之一。 编写并运行客户端和服务器程序。在 UNIX 中使用 C 语言, 正在关注

回答 5 投票 0

Apple IOS 应用程序和 Delphi TidCmdTcpServer

我有一个用Delphi编写的服务器进程,它已经投入生产好几年了。 它使用 TidCmdTcpServer 与客户端通信(也是用 Delphi 编写并使用

回答 1 投票 0

TcpClient:如何关闭并重新连接?

您好,感谢您的帮助。 这次想问一下TcpClient的问题。 我有一个服务器程序,我正在编写一个客户端程序。 该客户端使用TcpClient。首先创建一个新的 cl...

回答 4 投票 0

如何使用“C”在 Windows 中查找空闲 TCP 端口

我想要两个 Windows 应用程序,它们使用 Windows 套接字通过 TCP/IP 进行通信。在此,我希望我的程序自动选择可用的空闲端口来建立连接...

回答 2 投票 0

即使没有 TcpListener 正在运行,TcpClient 仍处于连接状态

我发生了一些我不明白的事情。 我有一台笔记本电脑通过 IP 地址为 172.* 的 VPN 连接到我的家庭办公室。 我在办公室有一个系统,我使用 10.* IP 广告远程访问该系统...

回答 1 投票 0

如何在没有源代码的 TCP 服务器应用程序中查找错误

我有一个 C++/cli tcp 客户端应用程序,以特定格式发送数据,如 L,20100930033425093,-5.929958,13.164021 到端口 9000 上的主应用程序。主应用程序实际上是由...完成的

回答 1 投票 0

使用 TcpClient 类 C# 的异步套接字客户端

我已经使用 TcpClient 类实现了套接字客户端。所以我可以发送和接收数据,一切正常。但我问了一些专家:)我的工具有问题吗...

回答 3 投票 0

问题:[WinError 10048] 通常只允许每个套接字地址(协议/网络地址/端口)使用一次

我正在尝试使用客户端-服务器模型编写一个Python程序,该模型支持通过对文件进行分段来将文件从客户端上传到服务器,并为每个片段创建一个线程来发送它。 我...

回答 1 投票 0

如何在抛出 SocketException 之前检测到已关闭的连接?

我尝试编写一个 TcpClientPool 来管理与主机的 KeepAlive 行为 公共类 TcpClientPool : IDisposable { 私有只读 ConcurrentDictionary _clients = ...

回答 1 投票 0

使用网络流发送和接收数据C#

嗨,我正在尝试将字符串从客户端发送到服务器。它不起作用,所以我尝试通过在同一台机器上发送数据和接收数据来测试下面的功能。 我遇到的问题

回答 2 投票 0

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.