Click here to Skip to main content
15,888,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 !
Posted

1 solution

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

VB
' 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[^].
 
Share this answer
 
Comments
Member 11687571 13-May-15 10:38am    
Thank you for the solution , Afzaal . I find it nice and helpful .
About TcpClient and TcpListener ( in vb.net ) - is it a more advanced solution to use TCP and the classes above to do the job and does it worth learning , or it is best best to go towards ASP.Net
Best Regards .
Afzaal Ahmad Zeeshan 13-May-15 10:48am    
I am glad if this helps you out. You can also mark it as solution. :)

In my opinion I would suggest that you move to ASP.NET instead of learning low-level networking classes (TcpClient and SslStream). ASP.NET's Web API would be a lot easier to you if you are beginner. You just need to have enough C# understanding and understanding of this Server/Client model. That is all that you would require to know. ASP.NET would wrap the requests and responses in easy objects for you to work with.

In the ports and streams you would have to write the same classes and objects to load the requests and read the streams and then generate the response... Which is already given in ASP.NET Web API.
Member 11687571 13-May-15 12:23pm    
Thanks again ! I will start a study over ASP.NET and its Web API . Hope that this brings
me in a few months learning to a nice and usable solution . I will accept you solution because the .vb networking is really not really easy for me to understand at this point . Best regards .
Afzaal Ahmad Zeeshan 13-May-15 12:26pm    
Thank you for accepting the solution. Also if you are willing to learn ASP.NET, you can find some useful resources in my profile (under Articles, Blogs and Tips) that would help you out. I hope they help you in learning ASP.NET.

You can convert C# code to VB.NET code using Telerik Converter.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900