需要建议 - VB.Net客户端/服务器的可能性 [英] Advise needed - VB.Net Client/Server possibilities

查看:60
本文介绍了需要建议 - VB.Net客户端/服务器的可能性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好日子亲爱的程序员,希望很快我成为同事:)。

我刚刚开始编程,但我仍然有一些使用Access VB编程的经验和对VB.Net的一个小概述。

但是让我们回答这个问题。

我想用服务器端和客户端构建一个不错的应用程序,它们都通过Internet进行通信。

客户端应该能够将数据(文件(包括图像),XML,字符串,整数,数据报)发送到服务器。

服务器应该能够接收客户端发送的数据,并根据连接到本地Mysql数据库的数据类型,做一些操作并用一些适当的数据回复客户端或者消息。

我预计可能会有超过20个连接(客户端)在同一时间运行。这是我搞砸了的地方,因为我读了很多关于TcpClient和TcpListener类的内容,编写带有同步流/网络操作的代码对我来说是清晰的,但异步仍然是一个大雾......

对我来说,你的主张是什么,考虑到我需要先知道从哪个设计开始,因此我可以提出更具体的问题。

一个设计我会说我的想法是什么,但是它是否正确并且还有其他可能性,哪个更安全,更容易实现?

我以为服务器和客户端都是Windows Forms App。

服务器将是多线程的 - 一个用于新连接的线程和一个用于读取消息的线程。 *问题 - 每时刻一个连接或每个时刻的多个连接。 Server将是一个TCPListener类。

客户端也将使用TcpClient类。

通常情况下,我仍然感到困惑的是,按照正确的方式做我想做的事......

欢迎给我一些指导帮助,从哪里开始。

提前谢谢!

解决方案

Windows窗体应用程序,但是因为你是允许多个用户通过同一个集线器(服务器)进行通信,ASP.NET将更好。如果您不想使用具有布局和其他形式的网站,请 ASP.NET Web API [ ^ ]对于此类应用程序将是



ASP.NET Web API允许您与通过不同位置连接的不同客户端进行通信,并允许您创建一个中心集线器(服务器)来提供响应通过客户提出的要求。关于这一点的好处是,它也可以在一个简单的控制台应用程序中运行。这被称为自我主持人。您所需要的只是一个可以在.NET框架上运行的软件应用程序(Console可以做到这一点,您最喜欢的Windows Forms应用程序也是如此)。 ASP.NET团队为您提供了一篇很好的启动文章: http://www.asp.net/web-api/overview/older-versions/self-host-a-web-api [ ^ ]。代码在C#中给出,您可以通过Telerik Converter轻松将其转换为VB.NET。因此代码将是



 ' 如果您已添加包并按照文章 

Dim config = HttpSelfHostConfiguration( http:// localhost:8080

config.Routes.MapHttpRoute( API Default api / {controller} / {id} 使用 {_
Key .id = RouteParameter。[可选] _
} )

使用服务器作为 HttpSelfHostServer(config)
server.OpenAsync()。Wait()
Console.WriteLine( 按Enter键退出。
Console.ReadLine()
结束 使用





所有请求都将在此处理。响应可以通过Web API进行,这里的好处是有机会以JSON格式流式传输响应。这对于缩短网络流量很有帮助,这通常是基于SOAP的框架(如Web服务)中的一个问题。



此外, TcpClient [ ^ ]和 SslStream [ ^ ]会因为你只是一个初学者而对你造成严重破坏。 就是不要!相反,现在尝试更轻松的事情。如果你真的想要进入网络,并希望使用套接字和类似的东西。快速(但彻底)阅读 系统。 MSDN上的Net 命名空间 [ ^ ]。


Good day dear programmers , hopefully soon I become a colleague :) .
I am just new to programming , but still I have had some experience with programming in Access VB and a a small overview over VB.Net .
But let's get to the question .
I want to build a nice app with a Server side and Client side , both of them communicating via the Internet .
The Client should be able to send data (files(incl images) , XML , string , integer, datagrams ) to the Server .
The Server should be able to recieve the data sent from the Client and according to the type of the data to connect to a local Mysql database , do some operations and respond back to the Client with some proper data or message .
I expect that there will be probably more than 20 connections(Clients) running on the same time . That is where I get messed up , since I read a lot about TcpClient and TcpListener classes , and writing a code with sync-ed stream/network operations is +/- clear to me , but the async is yet a big fog ...
What would be your propositions for me , taking in mind the fact that I need to know first what design to start from , and therefore I can be able to ask a more specific questions .
A a design I would say what is my idea , but is it right and are there other possibilities , which would be safer and easier to implement ?
I was thinking that both Server and Client would be Windows Forms App .
Server will be multithreading - one thread for new connection and one tread for reading messages . *Problem - one connection per moment or miltiple connections per moment. Server will be a TCPListener class .
Client will be using also TcpClient class .
Normally I am still confused about is that at all the right way to do what I want...
Feel welcome to give me some guide help from where to start .
Thank you in advance !

解决方案

A Windows Forms application would be good, but since you're going to allow multiple users to communicate through the same hub (server), ASP.NET would be better. If you do not want to use a website, with a layout and other formalities, ASP.NET Web API[^] would be best for this type of application.

ASP.NET Web API would allow you to communicate with different clients connecting through different locations and would allow you to create a central hub (server) that would provide responses to the requests made through clients. Good thing about this is that is can run in a simple Console application also. This is known as "Self-Host"-ing. All you need is a software application that can run over .NET framework (Console would do the thing, so would your favorite Windows Forms application). ASP.NET team has a great kick-start article for you already read at: http://www.asp.net/web-api/overview/older-versions/self-host-a-web-api[^]. The code is given in C#, you can easily convert it to VB.NET through Telerik Converter. So the code would be

' Provided you have added the packages and followed the article

Dim config = New HttpSelfHostConfiguration("http://localhost:8080")

config.Routes.MapHttpRoute("API Default", "api/{controller}/{id}", New With { _
	Key .id = RouteParameter.[Optional] _
})

Using server As New HttpSelfHostServer(config)
	server.OpenAsync().Wait()
	Console.WriteLine("Press Enter to quit.")
	Console.ReadLine()
End Using



All of the requests would be handled here. Responses can be made through Web API, good thing here is that get a chance to stream down the response in JSON format. Which would be helpful for you to cut-short network traffic that is usually a problem in SOAP-based frameworks such as Web Services.

Also, TcpClient[^] and SslStream[^] would cause a havoc for you since you are just a beginner. Just don't! Instead try something easier for now. If you really do want to go down in networking and want to use the sockets and something like that. Give a quick (but thorough) read to System.Net namespace on MSDN[^].


这篇关于需要建议 - VB.Net客户端/服务器的可能性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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