Socket.IO & Express alternative for C#? - c#

I'm looking to see if it's possible to create an application using C# that creates a local web server and allows me to pass information from the server, to the client website.
I've been using Node.js with Express to create a local web server and then using Socket.io to pass information through to the client, to display in realtime with Javascript. Only issue is I'm more comfortable with C# and I'd like to distribute this application, with Node Modules and Electron the app is clocking in at around 150MB, it's also many files and folders as opposed to just a .exe
Details of Application:
Reads data from log files
Decodes Json inside files
Sends specific data to website
Client receives data and displays
I've managed to get halfway there by using HttpListener, but from what I understand I cant send data to it? So I figured I could edit the html before I sent it and have yet to setup the FindDivByID method
TLDR; Is there a way to create a Local Web Server (Application) that is able to send data to the Client Website.
EDIT: Thanks for the suggestion, though I'm hoping to keep it all down to one distributable application, that reads the data from the local PC, creates the web server and sends to the clients

Well, if you wanna go full C#, I'd recommend SignalR, very solid
https://www.asp.net/signalr
Alternatively, you could keep your Socket.IO server in Node.JS and use this Socket.IO C# client library to interface with it (although I never really did tried)
https://github.com/Quobject/SocketIoClientDotNet

Related

How to connect ASP NET web app client with NET framework console app server

I need to develop a NET Framework MVC web app that takes 5 items in a form, each one consisting in a description and an image. I need to post these to a server app (locally) that takes this data and stores it in an XML file for example (No need to use relational DB). My server app is a console based in NET Framework. When I change the description of the file in the server, I have to display in "real time" the updated values in the ASP NET web app in the client side, so somehow I need to send back the values of the file back to the ASP NET web app. I have been looking to signalR but seems to be more suitable for instant messaging rather than working with files, so I thought websockets would be a good idea. Doesn't seem too complicated but I have never worked with websockets so I wonder if this is possible to do with my suggestion above so I have a few questions:
Is it possible this flow of data between an ASP NET web app and a server console app? would it be better to create a web API in the server to handle this?
How can I send data from the client web app to the console, is via URL a good option?
Can anyone suggest a simpler or more feasible solution to this?
I much appreciate some help here.
I would choose building an API since you can send the updates whenever they change, no need to wait or keep connections open.
If you really have to send updates in realtime, SignalR combines different ways of keeping a connection open, so it could be the best option.
I prefer using SimpleTcp to easily establish a tcp communication between server (web app) and client (desktop or console) so this is also something you can consider.
SignalR already has websocket implementation. Your solution could be for example creating the signalR hub inside the console application and then using the webapp to connect to it. On either end you call a method that changes the other side.

C# silverlight application server

I am building an application that needs to connect to a server to send and retrieve data constantly.
at first i was going to use mysql, by mysql is far from what i want. using this would force users to connect to the database constantly.
CAN C# silverlight connect to a server and send a message?
here is an example to something in C# console, VERY similar to what i am trying to achieve
https://www.youtube.com/watch?v=9kcrTKj7Jpk
Any documentation would also be helpful.
To be more specific my server will be written with C# console, but i want my c# silverlight to send the message.
Yes.
CAN C# silverlight connect to a server and send a message?
Traditionally, the way that Silverlight has connected to a server to send a message is with WCF services. This still works well, but the other option is REST.
What you will need to do is write a layer (or use an ORM like Entity Framework) to persist data from whichever database platform you choose (MySQL or otherwise). Then you will need to write REST, or WCF services on top of this. You will then need to consume the services from your Silverlight application.
There are many articles on this if you Google. Here is one of the ones that comes up instantly:
http://www.dotnetcurry.com/ShowArticle.aspx?ID=228
One thing you must consider with Silverlight, is that by default, Silverlight will only talk to the server that the Xap package is hosted on. So, if you need the Silverlight app to talk to a different server, you will need to set up and expose a clientaccesspolixy.xml from the server where the WCF/REST services are hosted. This is a stupid limitation that Microsoft made a big mistake on in the first place. Here is an article about it:
https://msdn.microsoft.com/fr-fr/library/cc197955(v=vs.95).aspx

How can I access a client side dll from a server side application?

In my current project we are trying to integrate a card reader into a
website. The problem is that we have to have the Windows Service
sitting on the clients machine in order for the card reader to work.
The purpose of the website is to have the client scan the card through
the card reader and have the information be sent to the database
through a web service. After the information is saved to the database
it can then be retrieved and shown on the site.
The question I have is
how can I access a .dll, that I have written, from the the asp page
sitting on the server. I know that I could use ActiveX but I am trying to
access the .dll in a way that will allow me to have the webpage be used in
as many browsers as possible.
I am thinking of using silverlight to try and access the dll. The .dll in
question is one that I have written and am trying to access. I've also looked
at trying the DLLImport but I've not been able to get it to work. I am currently using
.NET 4.0 and am writing in C#.
If your client is reading a smartcard, it might be a good idea to use the built-in windows features to use a smartcard to authenticate to IIS on the remote computer. If you're trying to read anything else from the smartcards, then it's usually better to offer the client a normal installer that registers itself as a security device, Browsers have built-in functionality to communicate to such a device. Our local bank, ABN AMRO, uses such a device which is sold by Todos AB and which comes with a driver that works in this fashion.
If you want to do anything else with the smartcard (anything other than reading a certificate or a security token, you'll probably have no other option than to offer the user with a download that I'd personally would always deny.

How to create and save a text file with JavaScript

Do you know any cross-browser method to create and save a file with JavaScript on the client-side?
Considerations:
I can't save it on the server because the file is going to be read from a fiscal printer.
The server can't access the client. This is obvious because we are talking about a web application in the web, so the server can't access a client folder.
New ActiveXObject("Scripting.FileSystemObject"); is ONLY for Internet Explorer and even then not for all versions.
We are talking about printing on a fiscal printer, so I can't ask the cashier in the supermarket to download the text file and save it in a folder where the fiscal printer can read it.
If not JavaScript, what else can I use in my ASP, .Net 4.0, C# web application?
Basically, you said it, "we are talking about a web application." Do you know any web applications that save a file to your hard drive (besides cookies) without showing you a download prompt first?
Having said that, browsers have started to offer a persistence API that goes beyond cookies. (See, for example, this article.) But such a solution wouldn't meet your requirement of being cross-browser.
Your only options are to use persistance APIs from HTML5 or to create a browser plugin (activex control on IE, NPAPI plugin on others) that can do the file access for you. You could use FireBreath to do this, and it would be relatively simple if you know C++.
That said, it is a really dangerous idea; it is difficult to prevent people from using your plugin in other pages, so your plugin has to somehow be smart enough to keep itself from being abused by malicious sites that want to read (or even write) arbitrary data to your hard drive.
There is, after all, a reason why browsers don't natively support this. I'd look at HTML5.
you can do that by Client side Web services just make a function in web service to create a text file in your hard drive then convert the web service in to the client side service when u do that .Net framework make a client side java script then u will be able to call the server side function using Java script in client side after that your file will not be posted in the server it will remain save in your hard drive ok
we came out with a simple windows service nodejs app to be installed in the local machine.
When the web application need to create a file it just sends an API call to this app using localhost and that will write the file for it.
Cheers.

Connecting C# Back-end with PHP frontend

I have a code written in C# I would like to use as the back-end of a site I'm building.
I would prefer not to build the site front-end in ASP.NET (which integrates nicely with C#), and to use PHP or Python instead.
Is that reasonable? Should I re-consider using ASP.NET?
How can I achieve that?
Just use asp.net mvc framework for the frontend instead of plain asp.net. It's easy to learn. And if you know php it will be easy to you undestand asp.net mvc.
I don't see the reasons if you are using c# backend use php frontend. For sure you can create service layer on c# and communicate with php through it, but it does not make sence for me.
You can do whatever you like. Personally i wouldnt use php because i dont know very much php.
But you can do it, you could expose a soap web service and there are libraries that will let php talk to it.
No one here will be able to tell you what you haven't already told us. Asp.Net will probably be easier because of how everything integrates and you can share classes etc - but that does not mean you HAVE to use it.
Both of them are fairly passive server side technologies that present html to browsers though. why do you need 2 servers?
You have to ask why you are doing it .. if you are playing and want to learn then of course you can do it just to see how it all works. But if you are on a commercial project then id suggest that you dont need both a php and a c# server ... or if you do perhaps you want to go asp.net for your web server and if you need another layer of services behind then use WCF if you want to go a microsoft route. Howver it is usually possible to host all services in the same IIs instance.
You can do this i have done this for a web site my self use a database server or files,
http://dtpgroup.co.uk/
Your C# application can connection to your store save the info it needs to then php can read them if it file just use a formatted file E.G
if your using Database php can connect to MySQL or MSSQL so your C# application can use MySQL if you know what your doing in C# if not and your more comfortable in php then use MSSQL (also php have the superior documentation )
I work in both frequently
Ugh, in normal instances, reading data with C# writing it to files and loading up with PHP sound slow, inefficient and down wright crazy. I believe these terms are being used wrongly.
Client Server - user machine - database great for private networks where you connect to the DB without going over the internet
vs n-Tier
Client - Browser programming html, css, javascript connects to middleware over the internet
Middleware - inside your firewall, connects browser to database could be called part of backend - php and C# are middleware languages
Database final (generally 3rd) tier
With php and c# you are creating multiple middleware layers
why why why would you do this for a web app pick one
now if you have a web app with PHP and sneakerware in house client server apps that are controlled ie shipping, accounting that are not exposed - maybe but you have added complexity that you would not need (generally)
Gary

Categories