C# Program working with PHP server - c#

Just curious about the best way to go about this. I want to make a webpage that shows the amount of time it takes to ping all the machines on my network. I want a C# program to do the pinging and report it to the webpage. I want to be able to click "Re-ping" on the webpage and the program rerun the test. What is the best way to go about this?
The biggest issue is how to get things from the user to the C# program.
I can make the program post on the server, and the server show the user, like below.
User <----> PHP Host <---- C# Program
However how could I get data to go the other way?
PHP Host ---?-->C# Program
Am I thinking about this all wrong?
I do want the pinging and other things to be handled by a C# program as it has far more complex functionality (threading, connections, etc) than a PHP host that is interpreted as it is requested.
Is it possible that I could let the C# program return pages to users and avoid a PHP server all-togeather?
Any ideas are welcomed.

You have many options. If you want to avoid using a PHP server the simplest would probably be to write a simple http server similar to this. Other options include using ASP.NET with a C# backend, or a webservice, which would be accessed from the PHP script or directly by a client application.

Related

Socket.IO & Express alternative for 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

How can I automatically portforward and use RDP?

The end goal is to connect to a computer through the internet not over LAN with an IP.
Let's say I have the program that allows a user to connect to it on one computer (server)
And the program that connects to the user on another computer (client)
On the client program, I have...
microsoft terminal services active client 1.0 and I'm trying to get that to display the screen of the computer that is running the server.
I've read that I have to get portforwarding done first of all and I can't seem to even figure out how to do that dynamically.
I'm just a bit overwhelmed is all. Any ideas on how to first start portforwarding dynamically? Or is there any other way?
I'm trying to do this in VB.NET but I understand C# as well so any examples in either code would be great!
I found an alternative of what I wanted to do but better.
I'm using this DLL
https://cdot.senecacollege.ca/projects/vncsharp/
and I'm also using
http://converter.telerik.com/
to convert from C# to VB.NET

C# Use/connect to MySQL database in webhost (One.com)

I want to connect to my one.com webhost, by using my C# winforms application. The support said extern connections is NOT allowed, then how am I gonna read the database table on my webhost? I was told that if I used PHP on the website, then it would work, and it does. But how should i access that code from my program and make it return some values?
Any help will be appreciated. thanks in advance.
PS. If i'm unclear somewhere, or if you need more information then just explain what's needed.
Your webhost has probably restricted the access to your database so that only a specific host can connect to it, namely the one hosting your PHP based website. This is a common practice.
If this is the case, you cannot connect from any other host - and thus, your C# winforms app won't be able to connect either.
So a direct connection from your C# app to your database isn't an option, but you might implement a REST interface with PHP that serves the data you need to the outside world. This could then be accessed by the clients using your C# app. This is the only solution I can think of.

Which programming language should I use for TCP server for JavaScript clients?

I am asking for advise on which programming language is most acceptable for the following situation.
The program will act as the server in a TCP networking application, serving JavaScript clients that output to the browser, using a pre-written framework.
The server program will need to be 'always-on', and be capable of dealing with JSON.
My first instinct is to use PHP, because it can run the same web-server, and has pre-existing JSON and TCP functions. Is there a way to run PHP scripts on the server without needing to have a browser open to 'trigger' the script execution? - the script will have to be running for hours on end without timing out.
Other languages that are considered are C#, C++, Java.
Thanks in advance.
node.js
The first example on the homepage shows how easy it is to build servers in it
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');
Anything can make a request that triggers a PHP script to be executed, it doesn't have to be a browser. For example, a cron job can simply request a particular page and it will be executed. Or it can execute it directly.
It looks like you are trying to run a php script to push data to the browser in real time. PHP is not ideal for this since it is io-blocking and will become terribly slow/crash when there are not enough available threads. This makes it very bad from a scalability standpoint. Java is ideal for this since it gives you the ability to control how threads are handled. If you are indeed looking to push data to your browser in real-time, xhr long polling is what you want. APE-server is by far the best solution I have found for this:
http://www.ape-project.org/
As a side note, you can run php scripts serverside without a browser. For a linux system, you will need php-cli to do this. To get php-cli, in terminal, type in sudo -s, hit enter, type your password, hit enter, type sudo apt-get install php-cli, hit y, then hit enter again. Then, create a file called yourfilename.run in the same directory as your php file and insert the following into the .run file:
php -f name_of_php_file.php
Allow the file to be executed in terminal (by right clicking it and selecting it), then double click it to open it in terminal. Voila, your script is running without a browser.
But once again, if you are trying to push data to your browser in real-time, php is a bad choice. Take the time to look into ape-server.

What's the simplest & most efficient way of telling if your code is executing on the client or the server?

I have an ASP.NET (C#) class that is used both on the client and server.
Depending on whether the code is being executed on the client or the server, it needs to behave differently.
What is the simplest & most efficient way of telling if the code is executing on the client or the server?
Thanks!
unless you are running Silverlight 2 or Silverlight 3 There is no way for Asp.Net to run C# code in the client (the users' browser)
It's executing on the server. Unless you are using Silverlight, C# is probably not run on the client.
Unless we're talking Silverlight here, there's not much choice: C# code is always executed on the server, JavaScript is executed on the client.
By your tags I see your talking about a web application not a client-server winforms app.
If it is in javascript, html and css, or silverlight it's happening in the browser. If it is happening in C#, it's happening on the server.

Categories