Control a raw socket from a web interface - sockets

I have an microprocessor which I can control through a raw tcp socket. I can control the device through a desktop application, but I now want to be able to control it via the web. I've done lots of reading but I'm struggling to find the best method to do this. So far it seems creating a socket server in a webserver such as Tomcat or Jetty is the best option. When the user clicks a button the command is then sent to the micro processor. Is this a viable approach or are there better methods?
It is important that the system is very responsive, in other words, when the user clicks a button on the web page, the microprocessor must receive it as soon possible.

imo...separate your concerns
first write the code that implements the behavior you want with the microprocessor in such a way it is generally useful, and then plug on whatever sort of controller you want, be it web page, junit test, command line interface, whatever.

Related

Can I access the source code of a PuTTY telnet server?

I'm sorry, I don't know how to phrase my question better.
For homework, I've been given a telnet server IP and Port that I connect to with PuTTY.
I was wondering if it is possible to view the source code of that server?
It is my first time learning about telnet and using PuTTY, and I don't know anything about it. I was just wondering if it is possible to view the source code of a telnet server, and if it is, how to do it.
Thanks.
I guess the idea behind this question is that if you're looking at a webpage you can do "view source" in the browser and look at the HTML, CSS, and Javascript that make up that page.
Of course, what you're seeing there is just the "client side" part of the web page. You can't click "view source" on Facebook and see the code that accesses their database, decides what to show in your feed, picks out the ads you're going see, etc., because that's all done server-side. Nor can you see the source code for the web server that handles your incoming connection, etc.
In the case of a telnet server, the "client side" portion is just the raw text you're seeing. There's nothing [1] analogous to what you'd see if you did "view source" in a browser beyond what you're already seeing in your telnet window.
Of course, if the program that they're running on the server side is publicly available, you may be able to download and read its source code. This is analogous to how, if a web site is running on apache or nginx, you can just download the source code for those and read them. But this is not something that's sent over the telnet connection.
[1] Slight nitpick: I guess technically if the text you're seeing has VT100 control sequences to highlight or colorize the text that is sort of analogous to HTML code, but it's very limited. If that's what you want to know about, you could either set your telnet client not to process those sequences in order to see what they look like, or you could capture the network traffic with something like tcpdump. But you can also just look up VT100 control sequences.

How to work with Ports on Webpage?

There are many programs written VB6 that use TCP ports.
Some of them listening, server out web pages, for example: 192.168.1.2:5352, when I go to this page, I see a page that allows me to control the VB6 program, This means there are some options that the programmer put on the page)
I want to know how to do this with my program listening on a TCP port (6006) and how to put some commands on a page, for example a textbox and button, so that when I enter something into the textbox on the page, my program displays in a message box.
Thank You!
It sounds like you're looking for an HTTP server component that you can embed in your application.
This can then serve out standard HTML pages that post data back to your app with a normal POST or GET request.
You can either do this with plain TCP sockets via the WinSock control and manually parsing the HTTP requests, or by using a service built into windows like the HTTP Server API but this is very difficult to use from native VB6.
Alternatively, you could loop at a plugin or CGI application with IIS or similar that communicates with your application via another method, maybe windows messages or named pipes.

Streaming data from web-server, trying to use vb.net and cgi

I need to stream data from a web server to clients. The data is location data that is collected and stored on the server. The clients will click a button on an html page to 'opt in' to start receiving the data. This data is never ending and there is at least one of the clients that needs to receive the data 24-7, with as few breaks as possible. The data being streamed will be client specific, as each client wont receive the exact same data.
I've done several multi-threaded tcp servers over sockets, and websockets are the way I would like to attack this, but the requirements are that this has to work in ie9.
The initial requirement was that this be a vb.net cgi executable - but during testing, I havent been able to 'use' the stream from the vb.net executable until the app finishes - like it wasn't able to flush the stdout even though I was specificly using the console.out.flush(). So If this isn't a viable option, and I can support this with facts, then I can get this requirement changed.
I've also read quite a bit about using a third party server to stream the data like Orbit and APE I think was a couple of them, but requirements are for 1 server - the web server. No other hardware can be required.
I'm pretty sure the vb.net CGI isn't the ideal solution based on what i've found, but is it doable or do I need to abandon that solution and move on to a newer technology , ISAPI? Any ideas or suggestions, even if they just point me in the right direction, are greatly appreciated.
You might go few ways.
If you would go C# .Net, then you might look into Silverlight solution. But it requires plugin in browser to be installed (like Flash). Good thing here, is that you are able to send data through normal sockets, in pure realtime from server. In same time Silverlight uses .Net so it makes some code to be shared. That helps development process. As well the way it will work in different browsers will be same.
You might have a look in similar solution using Java Applet with Java backend (can be even .Net, but again, easier to develop when both in same language).
Another option is to have fron-end using WebSockets, but as you know its not supported in IE9 and below (IE10 promises to be), and Opera is not supporting it as well.
Backend can be done in what you prefer. But bear in mind that WebSockets uses framing, and for constant but little packets its not efficient, because if you send 10 bytes, then it will create frame 2-12 bytes, and TCP packet header that is 40 bytes in average.
To support older browsers you might have a look in long-polling, but it is not as reliable as websockets.
As well it is important to calculate the amount of data and approximate amount of users that will use your system. Based on calculations you will have approximate information about how real it is, and what server will be required to handle.

See what website the user is visiting in a browser independent way

I am trying to build an application that can inform a user about website specific information whenever they are visiting a website that is present in my database. This must be done in a browser independent way so the user will always see the information when visiting a website (no matter what browser or other tool he or she is using to visit the website).
My first (partially successful) approach was by looking at the data packets using the System.Net.Sockets.Socket class etc. Unfortunately I discoverd that this approach only works when the user has administrator rights. And of course, that is not what I want. My goal is that the user can install one relatively simple program that can be used right away.
After this I went looking for alternatives and found a lot about WinPcap and some of it's .NET wrappers (did I tell you I am programming c# .NET already?). But with WinPcap I found out that this must be installed on the user's pc and there is nog way to just reference some dll files and code away. I already looked at including WinPcap as a prerequisite in my installer but that is also to cumbersome.
Well, long story short. I want to know in my application what website my user is visiting at the moment it is happening. I think it must be done by looking at the data packets of the network but can't find a good solution for this. My application is build in C# .NET (4.0).
You could use Fiddler to monitor Internet traffic.
It is
a Web Debugging Proxy which logs all HTTP(S) traffic between your computer and the Internet. Fiddler allows you to inspect traffic, set breakpoints, and "fiddle" with incoming or outgoing data. Fiddler includes a powerful event-based scripting subsystem, and can be extended using any .NET language.
It's scriptable and can be readily used from .NET.
One simple idea: Instead of monitoring the traffic directly, what about installing a browser extension that sends you the current url of the page. Then you can check if that url is in your database and optionally show the user a message using the browser extension.
This is how extensions like Invisible Hand work... It scans the current page and sends relevant data back to the server for processing. If it finds anything, it uses the browser extension framework to communicate those results back to the user. (Using an alert, or a bar across the top of the window, etc.)
for a good start, wireshark will do what you want.
you can specify a filter to isolate and view http streams.
best part is wireshark is open source, and built opon another program api, winpcap which is open source.
I'm guessing this is what you want.
capture network data off the wire
view the tcp traffic of a computer, isolate and save(in part or in hole) http data.
store information about the http connections
number 1 there is easy, you can google for a winpcap tutorial, or just use some of their sample programs to capture the data.
I recomend you study up on the pcap file format, everything with winpcap uses this basic format and its structers.
now you have to learn how to take a tcp stream and turn it into a solid data stream without curoption, or disorginized parts. (sorry for the spelling)
again, a very good example can be found in the wireshark source code.
then with your data stream, you can simple read the http format, and html data, or what ever your dealing with.
Hope that helps
If the user is cooperating, you could have them set their browser(s) to use a proxy service you provide. This would intercept all web traffic, do whatever you want with it (look up in your database, notify the user, etc), and then pass it on to the original location. Run the proxy on the local system, or on a remote system if that fits your case better.
If the user is not cooperating, or you don't want to make them change their browser settings, you could use one of the packet sniffing solutions, such as fiddler.
A simple stright forward way is to change the comupter DNS to point to your application.
this will cause all DNS traffic to pass though your app which can be sniffed and then redirected to the real DNS server.
it will also save you the hussel of filtering out emule/torrent traffic as it normally work with pure IP address (which also might be a problem as it can be circumvented by using IP address to browse).
-How to change windows DNS Servers
-DNS resolver
Another simple way is to configure (programmaticly) the browsers proxy to pass through your server this will make your life easier but will be more obvious to users.
How to create a simple proxy in C#?

How can a web page communicate with a local rich client application

I need to implement a process where users punch in a few details into a web page, and have this information fired as some
sort of an event to a Java rich client application (SWING) on the same host.
One idea was perhaps implementing an applet that would initiate socket communication with a listener implemented by the SWING
application, but not sure whether this is possible at all.
This sort of puzzling piece of integration is basically a given fact.
Essentially both the web application and the SWING one are already active and in use.
The only missing bit is sharing info between the two, in a way that would be easy to implement. no matter how dirty.
Any ideas?
Thanks!
Sounds a little confusing to the user if nothing else.
I would go one of two ways.
Have your rich client communicate over the network. And put whatever form you were going to have in the browser there.
Put your rich client into an applet.
Have both connect to a server somewhere (even locally), which your rich client can poll to see if the form has been filled in.