TCP / IP客户端问题 [英] TCP/IP client problems

查看:122
本文介绍了TCP / IP客户端问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我正在进行TCP / IP通信,以便在工业机器人控制器和普通PC之间进行通信,所以基本上我正在为客户工作这将是在PC上运行的程序的一部分。

I'm working on a TCP/IP communication for communicating between industrial robot controller and regular PC, so basically I'm working on a client which will be the part of a program running on a PC.

我做了一些研究并在Daniweb上找到事件驱动的异步客户端示例( https://www.daniweb.com/... /人性化,异步事件 - ... )。
所以我的客户端基于那个稍微改变的类,比如没有接收超时,因为如果机器空闲,我很长时间都不会收到任何消息。

我测试了我的客户端针对SocketTest 3.0。在正常情况下一切正常,但由于软件将在工业环境中使用,因此需要正确处理可能的故障,这就是我从代码中除外的事情。

I did some research and find the event driven asynchronous client example on Daniweb (https://www.daniweb.com/…/user-friendly-asynchronous-event-…). So my client is based on that class with minor changes, like no receive timeout, because if the machine is idle I will not get any messages for a long time.
I tested my client against SocketTest 3.0. At normal conditions everything works fine, but because the software will be used in industrial environments the possible failures needs to be handled correctly and that's what I was excepting from the code.

所以我做了一些进一步测试......

So I did some further testing...

1。客户端仍然打开并连接时关闭服务器。

短时间后触发ConectionStateChanged事件。由于在函数cbDataReceived中检测到错误,因此触发实际事件。那么是否可以在代码的接收部分检测到服务器的缺失?

1. Close server when client is still open and connected.
After a short period of time the ConectionStateChanged event is triggered. The actual event is triggered because of error detected in function cbDataReceived. So is it expected that the absence of the server is detected in the receive part of the code?

2。断开以太网电缆。

实际上没有任何反应,即使send命令也没有问题。因此,如果我按下发送测试按钮n次并发送x数据,而电缆仍然拔掉,则不会发生任何事情。然后,如果我将电缆插回,那么在我再次按下发送按钮后我将不会发生任何事情。然后服务器将收到x数据,n + 1次。

2. Disconnect the ethernet cable.
There is actually no reaction to that, even the send command goes through with no problem. So if I press the send test button n times and send x data while cable still unplugged nothing will happen. Then if I plug the cable back nothing will happen until I press the send button again. Then the server will receive x data, n+1 times.

我为我可能的坏术语道歉。我的职业不是计算机工程。我必须知道TCP / IP中的工作原理,但那是几年前的事情,而且主要基于理论方面。

I'm apologizing for my possible bad terminology. My profession is not a computer engineering. I had to know how things works in TCP/IP, but that was a few years ago and it was mostly based on theoretical aspects.

我愿意接受任何建议。 Daniweb类解决方案是否是正确的方法?如何以正确的方式处理连接可能发生的所有问题?如果有任何可用的库(甚至是商业库)可以帮助我解决
问题,请随时将它们写下来。

I'm open for any suggestions. Is the Daniweb class solution the right way to do it? How to handle all the problems that can occur with a connection the right way? If there are any libraries available (even the commercial ones) that will help solve me the problems feel free to write them down.

非常感谢您提前帮助。

Thank you very much for help in advance.

推荐答案

我使用Daniweb代码作为我自己的TCP侦听器的基础... Daniweb这是一个很好的开始,但我最终需要调整一下。我现在无法查看我的代码,但是我会尝试从现在开始几个小时到达它,看看我是否可以给你
任何指针。不幸的是,我不确定我能给你多少实际代码,而且在我看之前我不会知道多少。也许只需要几个指针就足够了。

I have used the Daniweb code as the basis for my own TCP Listeners ... Daniweb was a good start, but I ended up needing to tweak it quite a bit. I'm not able to look at my code right now, but I'll try to get to it a few hours from now and see if I can give you any pointers. Unfortunately, I'm not sure how much of the actual code I can give you, and I won't know how much until I look at it. Maybe just a few pointers for you might be enough.

问题...你提到了针对SocketTest 3.0的测试......这是什么?听起来它可能有用......

Question ... you mentioned testing against SocketTest 3.0 ... what is that? It sounds like it might be useful ...


这篇关于TCP / IP客户端问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆