在服务器和客户端之间建立连接 [英] establish a connection between server and client

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

问题描述

你好,
我必须在服务器和客户端之间建立连接.只有一个服务器和这么多客户端.我必须在c Sharp.can中创建一个Windows应用程序.给我这个主意.
Thnx
问候,
Vishavdeep Goyal

Hello,
I have to establish a connection between server and client.Only one server and so many clients.I have to make a windows application in c sharp.can u plz. give me the idea about this.
Thnx
Regards,
Vishavdeep Goyal

推荐答案

使用 TcpListener类 [^ ]在服务器端.

有一个很好的入门入门示例.

使用C#在.NET中进行套接字编程的简介 [
Use TcpClient Class[^] on the client side and TcpListener Class[^] on the server side.

There is a good beginner example on how to get started.

An Introduction to Socket Programming in .NET using C#[^]


您可以使用多种级别的网络.
您可以考虑以下内容:

使用System.Net.Sockets.Socket的套接字级别较低,使用System.Net.Sockets.UdpClient(UDP),System.Net.Sockets.TcpListener/System.Net.Sockets.TcpClient(TCP)、. NET远程处理,WCF(是否为自托管)的套接字级别稍高.
较低的级别将需要封送处理和/或序列化;您可能还需要知道如何创建和使用DataContract和/或ServiceContract,尤其是对于WCF.线程和线程同步是最重要的方面之一.

我建议您不要尝试在应用程序之间进行通信(尽管这取决于您的目标).在服务(不一定是客户端服务器)和客户端方面进行思考通常会更有效率.

即使在每个级别上都编写最基本的示例,也可能会写出非常大的文章,可能……难以估计……数十页.谁来为您编写?最好尝试在CodeProject中查找单独主题的文章,并使用每种技术创建原型应用程序.只有这样,您才能感觉到它们足以决定应用程序上的设计.

基本建议:不要像某些人一样发送UI控件之类的东西.创建纯数据类型并发送纯数据;在数据和UI之间创建松散耦合,将UI与数据模型,通用功能和特定于应用程序的功能隔离.


—SA
There are several levels of networking you can use.
Here is what you can consider:

Low sockets level using System.Net.Sockets.Socket, a little higher socket levels using System.Net.Sockets.UdpClient (UDP), System.Net.Sockets.TcpListener/System.Net.Sockets.TcpClient (TCP), .NET remoting, WCF (self-hosted or not).

Lower levels will need Marshaling and/or Serialization; you may also need to know how to create and use DataContract and/or ServiceContract, especially with WCF. One of the most essential aspects will be threading and thread synchronization.

I would suggest you don''t try to communicate between applications (it depends on your goal though). It''s usually more productive to think in terms of service (not necessarily client-server) and clients.

Making even most elementary examples on every level would make a really big article, may be… hard to estimate… some tens of pages. Who will write it for you? Better try to find articles of separate topic in CodeProject and create prototype applications using each technique. Only in this way you will be able to feel them well enough to decide on designs on your applications.

Basic advice: don''t try to send UI controls and the like, like some do. Create pure-data types and send pure data; create loose coupling between data and UI, isolate UI from data model, universal functionality and application-specific functionality.


—SA


Google是您的朋友:很好,经常拜访他.与在这里发布问题相比,他可以更快地回答问题.

这不是一个新问题:使用您的主题行作为搜索词的快速Google 产生了将近4亿次匹配,其中大多数都说明了如何实现.
Google [<
Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here...

This is not a new problem: A quick google using your subject line as the search term gave nearly 400 million hits, most of which explain how to do it. Google[^]


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

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