Talk to javascript with c# and vice versa - c#

I am creating a website where I need to have access to the clients files. I know that the client will have to accept some warning message and also run my progam.
I have reaserched on the internet and I know that I can acomplish this with Web Sockets. I have been able to establish a tcp connection localy from c# and google chrom html 5 websocket. the problem with websockets is that it did not work with other browsers.
Another solution that I was thinking was to use cookies to exchange messages. I havent tried that and I dont think that will be efficient.
Some websites when giving them privilades are able to use java. I have no idea how they exchange messages but maybe there is a similar way of doing it with c#

Look at SignalR -- https://github.com/SignalR/SignalR. Be careful though, web sockets (and any other "per user" type connection has server resource implications -- see http://robrich.org/archive/2012/04/05/The-real-time-web-in-ASP-NET-MVC.aspx

Related

How to create a simple restful server / client solution in c#

I'm trying to create a server based around the restful api (basically a client - server system which listens on a specific port but all the tutorials I've seen were using asp.net, some databases or not suited / too complex.
I've tried The Msdn Tutorial, That One CodeProject and That Other CodeProject Tutorial and also haven't found a simple solution here either.
I was thinking of a solution like:
Server listens on specific port for restful requests (Lets call it "ServerListener") and handles the request then in a static "CheckNumber" if its either positive or negative. It'll then reply to the client with the value "positve" or "negative" (depending on its value). The client then shows a MessageBox with the result.
The final idea would be having the server being proxied by an nginx server which handles the the encryption with the client and sanitizing the request.
Please check https://msdn.microsoft.com/en-us/library/windows/desktop/aa364510(v=vs.85).aspx
The Http API will give you the freedom to implement your server without Asp.Net, without WCF, and even without IIS.
Check my post, it contains several examples for simple REST server implementations, including C#, Java, PHP and node.js.

Read data from com port since client, web application, C#, .NET, Razor, MVC4

Good day, I created a web application using razor, mvc4 and c #, what happens is that I need to read some data traveling through a COM port on the computer, on the server it runs smoothly, the disadvantage is that I need to read the data through com but from every PC you open the application, not necessarily from Server, is it this possible ?, thank you very much.
Web browsers do not allow serial port access. And this makes sense because if a malicious web site could just read and transmit data through a client serial port, it'd be a serious security issue. There are only 2 ways to do this:
Using a rich internet technology, such as Silverlight or Flash. Both are being deprecated though.
Google Chrome has an API that you can access from Javascript. However, this solution will ONLY work on Chrome browsers.
You would have to write a browser plugin that allows access to the serial port, then each user would have to accept and install this plug in.

How to push messages from API server (PHP/rest) to C# apps

I have C# apps requesting data from PHP/MySQL API server (Rest/JSON). Now I also need to push messages to the C# apps when some events occur (form submission from the web site). I searched around, and it seems that COMET, long polling, and http streaming are options. Could you please provide some suggestions on which technology makes sense here, as I am not pushing to a web browser?
In addition, if using HTTP streaming (like twitter streaming API), do I need to keep a table of HTTP connections so I know which connection to use when pushing targeted events (only to certain C# clients)? I am a bit confused, and many thanks!
Make a WCF Web Service. http://www.codeproject.com/KB/WCF/WCFWebService.aspx
To connect using PHP: http://weblogs.asp.net/gunnarpeipman/archive/2007/09/17/using-wcf-services-with-php.aspx
In micro-services environment you might want to communicate between more different coding languages in the future, that's why in Kaltura we expose every API with descriptive XML that we can use later to generate client libraries in multiple coding languages, our code generator includes client libraries for C# and PHP.
I also published several REST server examples, including C#.

Is it possible to make a web-based telnet service?

I use ASP.NET MVC with C# for web development and I am curious about creating a web-based telnet server. I've actually never done anything with telnet, but I'm fairly certain I understand the basics of it as a simple protocol. Do I need to be running an application listening on a port to establish a socket connection with a client, or does telnet also operate in a request/response format so that it could talk to an MVC-style web service instead of an actual running server program listening on a port.
Let me know if I have absolutely no idea what I'm talking about. I really just need pointed in the right direction.
Keep in mind that I am talking about a telnet server, not a client.
Thanks in advance.
You can either create a telnet server, or a telnet client. But where is web in it? I can't see it. If you really want to make a server, you can simply make a telnet server and you don't need the web.
If you want to make a telnet client on a web page, it makes sense. Users will use their web browser, and your application will act as a bridge between the real telnet and web browsers. Your application will act as a telnet client on one side and transfer all data to and from human user using web pages. It is a real time thing so I would prefer client code for this, like Silverlight, where IMO you can achive quite good result.
You can telnet to a web server and interact with it over HTTP, but you can't make the server behave like a telnet server unless you bind to a different port and run telnet over that port. At that point the fact that your hosting it in a web server is pretty superfluous though, so I'm not sure why you would do that.

is there a way to let the web server (not the Client which is the trivial case) send a messege to a Client application?

I'm about to start to develop and application in C# but I realized that I haven't the enough knowledge to develop it yet :S.
The thing's that I need to find out a way to let the Web server comunicate with my application, i.e., in short, is there a way to let the web server (not the Client which is the trivial case) send a messege to a Client application?
I know that I way to solve it's to make Client applications periodically send messages to the web server but that's not what I want 'cause polling generates overhead
Sorry about my english! I'm not a native speaker.
Thanks in advance!
Generally this type of interaction is achieved with Comet or WebSockets - I'm not sure how your app will be communicating with the server, but I would bet you can do what you're trying to do using one of those.
You could implement a WCF service in your client that could listen for a connection from the server (or anything else). The server can communicate with the client as easy as calling the API.
Getting started with WCF is really easy using the wizards in VS.
Here is a link that talks about using WCF with ASP, but it can be used outside of asp as well.
It seems like you meant "push" messaging, the challenge around this is for the server to keep track of the lost of clients and manage who should recieve which message.
If you want to get it done with minimal overhead you can check out the Amazon Simple Notification Service.
SNS is a cloud-based messaging and notification service hosted and managed for you, SNS is based on a topic/subscriber model and you set it up via a few simple API calls, it is metered but quite inexpensive for the most part.
edit: For C# Libraries and frameworks to do it yourself, I am not an expert in the C# world so I think other answerers will know it better.
Disclosure: I work at amazon so I am naturally inclined to like their product

Categories

Resources