多个客户端连接到一台服务器 [英] multiple client connected to one server

查看:271
本文介绍了多个客户端连接到一台服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个应用程序,其中多个客户端可以与单个服务器连接.服务器和客户端都在Windows窗体应用程序而不是控制台应用程序中.
我已经完成了这个应用程序,但是当我们关闭服务器应用程序时,它给出了异常.
使用Windows窗体,使用c#在asp.net中给我正确的源代码

I want to make a application in which multiple client are able to connect with single server.server and client both are in windows form application not console application.
I have done this application but when we close our server application,it gives exception.
give me right source code in asp.net with c# using windows form

推荐答案

这是很正常的行为.不要尝试防止这些异常,只需在客户端中对其进行正确处理,在表单中显示服务器已断开"之类的状态,相应地刷新控件的状态(启用,禁用,更改文本),等等.

要取得进一步的进步,为什么服务器应用程序是表单应用程序?最好是Windows服务.这样,如果用户注销并且没有人登录,它将保持正常工作.当然,这需要更多的精力,但是…如果没有此服务,您将没有真正的服务.

您仍然可以通过UI来控制服务.

将我最近的答案用于另一个问题的一些想法:
使用UI配置Windows服务 [
This is quite a normal behavior. Don''t try to prevent those exceptions, just process them in the clients properly, show status like "Server disconnected" in your form, refresh status of controls accordingly (enable, disable, change text), etc.

For a more advances step: why the server application is a Form application? It should better be a Windows Service. In this way, it will keep working if a user logs out and when nobody logs in. Of course, it needs more effort but… without this you don''t have a real Service.

You can still have UI controlling the Service.

Use my recent answer to a different question for some ideas:
Configure Windows Service with UI[^].

—SA


这篇关于多个客户端连接到一台服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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