使用套接字编程的客户端服务器通信 [英] client server communication using socket programming

查看:139
本文介绍了使用套接字编程的客户端服务器通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在不同计算机上完美运行的客户端服务器通信应用程序.假设如果我断开客户端的网络电缆连接,那么我想在服务器端收到一条消息网络电缆已拔出".如何确定何时拔下网络电缆?请发送用于识别何时从客户端计算机上拔下网络电缆的代码.

I have client server communication application running on different machines perfectly. Suppose if I disconnect the network cable at client side then I want to get one message "network cable unplugged" on server side. How can identify when the network cable was unplugged? Please send the code for identifying when the network cable is unplugged from client machine.

推荐答案

这取决于您的服务器,以了解客户端是否已连接,一旦您的客户端拔下了网线,便无法传达这种情况.

例如,检查此文章

http://www.switchonthecode.com/tutorials/csharp-tutorial-simple-threaded- tcp-server [ ^ ]

看一下将实现这种功能的一些聊天"类型的应用程序.
It''s down to your server to know if the clients are connected or not, once your client has removed network cable there''s no way for it to communicate that this has happened.

e.g check this article

http://www.switchonthecode.com/tutorials/csharp-tutorial-simple-threaded-tcp-server[^]

Have a look at some ''chat'' type applications that will implement this sort of functionality.


据我所知,这并不容易,但有时我们会定期向确保客户端还活着,尝试几次探查后,如果我们仍然没有收到客户端的回复,我们假设客户端不再活着,并且连接已终止,但这仍然无法准确说明是因为网络故障,

但我认为可以使用c或c ++中的套接字选项来解决您的问题

这可以帮助您保持活力
http://docs.hp.com/en/B2355-90136/ch03s01.html [ ^ ]
according to my knowledge it''s not easy , but sometimes we send a probe periodically to make sure the client is alive , after trying the probe for several times if we still didn''t receive a reply from the client we assume the client is no longer alive and the connection is terminated, but still this doesn''t say exactly it is because of network failure,

but i think your problem can be solved using socket options in c or c++

this might help you keepalive
http://docs.hp.com/en/B2355-90136/ch03s01.html[^]


这篇关于使用套接字编程的客户端服务器通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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