Developing a program that serves as a web program in C# [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm not sure if I'm going to be able to explain it right since I'm quite sure I don't know the correct terminology involved with it, which is also why I'm having a difficult time Googling for answers.
Essentially, I'm looking to develop a program that serves as a web site. It'll run constantly (like a service) and will return HTML when an outside user sends an HTTP request thru a browser or similar to a specific port on the computer this program runs on. Basically, this program will perform various background errands throughout the day but I want to be able to expose a web front end (almost like how you would with standard WinForms, but I want to be able to access it remotely) to be able to configure it, check the status of tasks, and otherwise interact with it.
I'm looking to use .Net, but I'm open to using something more universal like Java too. Someone with experience in this area would be helpful to explain any pain points you've encountered and suggestions on how to get started.

You can do it in C# with the HttpListener class.
I published an example some time back. See A Simple Http Server.
Although you might consider whether you really want to operate at that low level. I have written a fairly complex server based on HttpListener, and if I had it to do over again I'd probably just bite the bullet and use ASP.NET. There is a bit of a learning curve, but unless your server is incredibly small and simple, an ASP.NET application will be a lot easier to write and will likely be more robust.

Here is a simple example on how to do it in C# using the HttpServer class:
http://www.codeproject.com/Articles/137979/Simple-HTTP-Server-in-C

You are doing at least 2 different things, so you should probably create a Solution in Visual Studio.NET with one project for each purpose (You can have many projects in a solution), probably with at least one Data Access project as well (of type Class Library). If the solution does things at certain times of the day, then those can be Console Applications that run through task scheduler, rather than one of more services. Services are better suited to things other than simple scheduled tasks. A Web Application project can serve up your html.

Related

c# solution architecture for signal-r and angular [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I would like to build a c# spa application using angular with real-time messaging signal-r. The signal-r should read the data continuously from a data source and publish the updated data to the user and store the data in a database as well. It should also enable the chatting of the users.The expected number of users is around a hundred.
For such application what should be the best architectural structure of the solution? Should I implement two (three?) projects, e.g. one for the web app and the other for the signal-r, running as two applications? Then, in this case, how can I do the messaging between the applications? Or should I implement a single project for all of these? It would be best if you can provide the pros and cons of these alternatives or provide any other option.
Start with one project.
For 100 simultaneous users, you aren't even close to worried about load. Any simple hosting plan would take care of it easily. If you get more, ASP.NET and SignalR work just fine behind a load balancer (though certain operations can get more complicated).
A properly architected application won't be difficult to split into multiple processes in the future if it ever came to that, and doing so now is just adding mounds of complexity for no appreciable benefit. This goes double since it sounds like you are just starting out.

Local Server for Gaming C# [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
[C#] Hello all, I am curious on how I can go about creating my own local server and allowing people outside to connect an return data stored on it. I am not looking for an "XNA" solution. I would like to kind of digest the bare bones of client to server. Here is an outline for what I am looking for:
My PC
[Server] -> Constantly Updates/Receives Player data so it can be obtained by other PC's. Stores data from other clients.
[Client PC] -> Writes to server (Creates new player data/updates) and obtains further information to update visuals, other players, etc.
This isn't something small that anyone can just do, especially if you are just getting into programming. I would first start out small, make a few smaller applications, play around with the .NET framework libraries and get comfortable (I would specifically look at System.Net/System.Net.Sockets as well as possibly System.Security for SSL encryption). The networking component will be huge in this as you'll need to implement a system to handle the constant communication and be able to respond quickly (any lag can be seen as dropped packets from a networking standpoint and cause client time outs). You'll also want to think about what kind of data you are serving up (saved games, player data, whether it's personal information (such as passwords, email addresses, etc)) and how you are going to store that data. There are many paid and free technologies for this (Postgres, SQL, MySQL, etc). Please do a quick google on some of thee items I have mentioned and you'll see why it takes years to develop games and the back end systems to support multiplayer.
If you are the type of learner to plug things in and learn by tearing someone else's code apart, I would take a look at some of the articles below.
http://www.codeproject.com/Articles/1415/Introduction-to-TCP-client-server-in-C
http://csharp.net-informations.com/communications/csharp-multi-threaded-server-socket.htm
Here's some MSDN articles dissecting the different classes of the System.Net namespace and functions of it.
https://msdn.microsoft.com/en-us/library/system.net(v=vs.110).aspx
https://msdn.microsoft.com/en-us/library/system.net.sockets(v=vs.110).aspx
https://msdn.microsoft.com/en-us/library/system.security.cryptography(v=vs.110).aspx
https://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.x509certificate(v=vs.110).aspx
You'll also want to look at using threading to make sure the server isn't only processing one request at a time. There are many approaches to this but here is some basic examples of using threads.
http://www.dotnetperls.com/thread
When to use Multithread? (Some pointers how on and when to use threads on our very own S/O site :) ).
Here's the DL on threading from MSDN
https://msdn.microsoft.com/en-us/library/system.threading.thread(v=vs.110).aspx
Not meant to discourage you but more to show you the type of effort you'll have to put in to this sort of project. What you want to do is completely doable, but will require some brain training and head scratching. Apologies if it sound condescending, just trying to coach and am unsure of your level of expertise in c#! Best of luck to you though friend, hopefully this turns into a great learning experience!

How to turn windows forms app into native ASP.NET? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have written a windows form app in C#, but I want to turn it into native code for ASP.NET so I can build a webapp around it. However, I've never used ASP.NET and I'm not sure how to approach this. I've looked around and seen libraries such as VisualJS.Net, but it looks confusing and I'm not sure if I can seamlessly integrate it into my app without causing problems later on. Could someone lead me towards the right direction?
Thanks!
So if I well understand, you would like to "transform" a Windows Forms app into a ASP.NET. The problem with this approach, is that those two technologies are like day and night. They don't have the same lifecycle at all. Windows applications are by definition stateful. This means that they keep their state in memory and they don't need to rebuild it often (maybe at the loading of a file). Web applications however are completely stateless. The server receives a request, processes it and returns web content (HTML, JSON and whatever is needed). If the server is again contacted with new information, the state must be rebuilt (with the help of cookies, sessions, etc).*
However, what you can do the ease those problems is the following. If you separate your concerns, you can more easily reuse your business logic and your data and just re-code the view of your application. This means that you must separate what belongs to a View technology (WinForms, ASP.NET) from the model itself. There are numerous patterns to support this : MVC, MVP, MVVM. Respecting GRASP patterns also helps.
With that in mind, you could have three solutions : One containing your common code, one containing the logic that belongs to WinForms and another one that contains your ASP.NET logic. It's easier said than done, but this should be the way to go.
You can't turn an apple into an orange. Those two technologies are so different, that you will be better off rewriting the application from scratch, and taking advantage of all the goodies available in ASP.Net MVC 5.
Technically speaking one could devise some type of a converter, but it would potentially promote bad coding practices, something you should avoid.
Start learning MVC 5, you will be better off in the end.

Upload a .net application online? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I'm about to do a project on financial data visualization. Nothing advanced really, just some user input manipulated and visualized as an output with some charts and numbers. The thing is though, that even though the plan is to have it as a .NET desktop application to begin with an idea is to later transform it into a web based application. And since I've got no experience with that whatsoever my question is simply: Can one write a desktop application in C# .NET and later "upload" or "convert" it into a web based interface without too much work?
I've heard of ASP.NET that seems to be a pretty well used framework for web applications, but I cannot find anything about converting a desktop application into ASP.NET application.
Thanks in advance!
IF you divide your application into parts as you should - e.g. business logic, data access layer etc (into different dlls preferably), then all you need to do is just create a new UI, which isn't as bad as creating the app from scratch...
There is obviously a confusion in definitions. You (and it seems some of the guys that posted their answers here) have probably misunderstood the technology.
You can't compare ASP.NET to C#, because one is a web framework, the other is a programming language. ASP.NET can and does use C# (or VB.NET or other .NET language). ASP.NET can then be divided to MVC and Webforms. If you want to compare it to something, you should compare it to windows frameworks like WPF and Winforms.
That said, if the two apps have the same functionality, the logic and the C# stays basically the same. The only thing that changes is the framework that's used for the UI. That's why I'm talking about dividing the app into subprojects, which you can then reuse as needed.
As far as I got your question, there is no way to convert a .Net Desktop Application to a web application. you will need to re-write it. sorry buddy.
Unfortunately not.
When you start developing your Application for Desktop (for example with Windows Forms) the differences to a Web Application are too big too automatically convert.
I suggest to make a web Application from the beginning.
MfG Mike
I think there are service/companies/utilities that do do that, but you don't hear a lot about them, prob because they are not great. I don't know of other technology families that do that better either.
If the eventual goal is a website, prob just start with the website and forget the desktop. Slower to develop and more to be aware about to be secure are the other downsides.
the downvotes are prob about the question already being asked. If you google "stackoverflow: C# desktop to website conversion", here are three posts that are similar, in descending order of informativeness.
Converting ASP.NET Web Forms application into Desktop Application
Can I convert from C# to asp.Net to host application online?
How to Convert C# Desktop Application Project to website

C# P2P Instant Messenger General Basis Help [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I want to start a simple windows P2P instant messenger in C#, similar to AOL, ICQ, etc, but much more simple (plain text messages between 2 guys)
I don't need examples on how to do it. I can find them myself.
What I do need is a general idea of how instant messaging works (P2P, not multichat) without many technical details.
For example:
Will I need a main server to make the communication between user1 and user2 happen or user1 can send the strings directly to user2? How is this called?
If user1 is logged in, how does he know of an incoming message from another user (or the online status of their friends)? Does the chat client app check every X seconds with a main server?
Any clues that might help me clear the general data flow idea will be very much appreciated.
A flowchart may also be helpful if you find one to share.
Thanks in advance.
UPDATE (NEW QUESTION) - July 6
Let's say the user had successfully logged in, and the app needs now to get and populate the list of contacts (saved on my apache/php/mysql server).
How would you implement the data retrieval (important) and later population of the contacts list? Is WebClient.DownloadString[Async] a good approach? Is there a better way?
How often should the app check for updated list (online/offline statuses). Recommendations accepted.
How can I parse JSON data on C#.NET (Visual C# Studio 2010)
I will get JSON strings.
Thanks!
If you really want to build a p2p app, there should be no server. However, this is not straightforward.
There are lots of different approaches to creating a chat system, mostly involving servers. Research comet (a good solution if implemented properly, terrible otherwise), polling (checking every x seconds) or using sockets, however there are lots of issues to be considered - and caveats, particularly firewalls/nat routers. A socket solution could potentially be 'p2p', but the polling and comet ones are not.
For your use case, I would go with a simple socket solution (one side as server, one as client) and configure your router firewall by opening a port at the server end.
You could extend this so that both sides could be both servers (listening on a port) and clients, so you could both 'call' each other.
You will need to have a permanent ip, or use a service like dyndns to get this to work properly.
Update
Yes, DownloadString or DownloadStringAsync would be a fine method.
How often is really up to you. I assume that this is only for a few users from what you said in the question, so you don't need to worry about overloading the server. Once a minute sounds reasonable, but once a second would proabably be fine too if you feel that way inclined... Parsing JSON in .NET answers your final query.

Categories