Sockets server that handles system commands and http requests - http

i've been searching and trying for weeks now to find a solution to my issue that I can understand and easily implement but I had no joy. So i would be very grateful if someone could put me out of my misery.
I'm building an iphone app similar in functionality to apps like "Air Video" and "Air Playit". The app should communicate with a server running on a remote host. This server should be able to execute a command sent by the iphone to encode a video and stream it over http.
In my case, my iphone app sends commands to be executed on a remote host. the remote host is running a python socket server listening for example on port 3333.
On the iphone, i'm simply using
"CFStreamCreatePairWithSocketToHost", "CFWriteStreamOpen" and
"CFReadStreamOpen"
to connect, write and read data.
My remote host, successfully intercepts the commands and starts the encoding.
To serve the contents, I'm having to run a separate http server (i'm using Python simpleHTTPServer) which is listening on another port.
What I would like to do is use the same port for both system commands and http requests.
The apps I've mentioned above seem to do it that way and I've noticed they have their own build-in web server.
I'm sure I'm missing something but please bear with me this is my first attempt at building an app.

Encode your system commands into special HTTP requests. Decide which thing to do (execute command or serve the contents) based on HTTP request, not on the incoming port. If you need to use separate http servers (like you told), consider having a layer that receives everything from the devices and dispatches to other servers (or ports) based on the request.

Related

Where to locate socket server on QT?

I created simple socket server on QT. I use it for messenger app. It just send received messege to all connected clients. All this works fine. To connect to server i use string 'localhost'. But where to place the server so that my friends can connect to it?
I know that i must put my server to any hosts, like wordpress, smarterasp(correct me if i wrong). But i don't know if it would work at host on QT. And i just don't know how to place my server to host.
Searching this information gives me just 'web server'. As i know web server use http for requests, so it won't work for me i think.
If it's possible, i'd like host with free trial for my server(because i want just to test it).
So the main questions: How and where put my QT socket server, that other people can connect to it by my app?
P.S My friend has paid wordpress, so theoretically i can use it (if it match)

How to simulate tcp connection loss on localhost

I have a ASP NET Core web api that uses websockets. I am trying to find out if the server handles internet connection loss (client side) correctly.
However since I have only one machine on which both the server and the client run, i know that localhost does not use the Network Interface, and the desired handler is not triggered when I cut off the internet.
How can I thus have a server that runs a localhost, and a client that also runs on localhost but uses the network interface, so that I can cut the internet off and see how the server behaves for the given client?
I use TCPView to do this sort of testing. You can find the connection in the list, then right-click/close it:

How to forward data from desktop application through fiddler or mitmproxy?

I am using a win10 desktop app for which I know it is sending TCP packets in order to communicate with the server. The payloads are encrypted. There is a chance that if the app is using TLS, a proxy like mitmproxy or fiddler will be able to decrypt the data.
The app also gets assigned different port every time it launches. So far the only promising information was to use netsh:
netsh interface portproxy add v4tov4 listenport=appPort listenaddress=appLocalIP connectport=fiddlerListeningPort connectaddress=fiddlerLocalIP
I ran this command after the app was already running because I can not determine its local port beforehand. But that did nothing. I was unable to find any other way to force the app to route the traffic through fiddler / mitmproxy.

implementing an MQTT server capable of serving a website too

short question : How can I host an MQTT server on my remote Ubuntu 16 server while at the same time hosting an HTTP server that will be using the MQTT data ?
true question : I want to build an IoT system that will be MONITORED and CONTROLLED by ESP32, which will SEND FEEDBACK and ACCEPT COMMANDS respectively from a remote server (maybe LAMP ?). I also want the user to log-in in a website hosted on this remote server, where s/he can monitor any sensor values or send commands (e.g. turning a led on or off).
So what's the way to go here?
I was adviced to go with MQTT but then the above problem arised.
what I've found : I 've found that using Mosquitto MQTT, I may be able to serve a website using websockets. But I prefer a more scalable HTTPS approach. That is, I intend to have a database linked with my site and running my PHP scripts.
I'm not that experienced, so please don't take anything for granted :)
MQTT uses TCP connection and follows publish/subscribe API model where as the web(http) follows Restful API model(Create,read,update,delete). If you want to stick with MQTT then you should use SAAS service like enterprise MQTT from HIVE which provide this integrability but will charge some fees and in return, they will provide you with an account and a dashboard for all your devices. Otherwise, you can try to make your own middleware which can integrate MQTT with web services .
Another thing I would recommend is CoAP which is also an M2M protocol but follows Restful API model and UDP connection. It has direct forward proxy to convert coap packets to https packets and vice versa.
In MQTT you have a central server(Broker) to which the nodes send their data and fetch their required data through topic filters.
In CoAP each device having some data to share becomes a server and the other device interested in it's data becomes a client and sends a GET request to the respective server to get its data. Similarly a PUT request along with a payload from a client would update the value at the server.
You really should not be looking to combine the MQTT broker with a HTTP server, especially if you intent the HTTP Server to actually be an application server (Running back end logic e.g. PHP). These are 2 totally separate systems. There is nothing to stop your application logic connecting to the broker as a client.
If you intend to use MQTT over WebSockets you can use something link nginx to proxy the WebSockets connection to the broker so it can sit behind the same logical HTTP/HTTPS address.

Jmeter and vpn connection

I have an app on mobile which runs through VPN connection . I am doing performance testing using jmeter on desktop for which I have done necessary configurations but http proxy server does not record my http requests
Can anyone help on this
JMeter and mobile device need to be on the same network in order for JMeter to be able to capture mobile device traffic. So the easiest option would be connecting desktop to the same VPN and using VPN-originated IP addresses.
You will also need to install JMeter's self-signed certificate, the relevant file is ApacheJMeterTemporaryRootCA.crt, it's being generated in JMeter's "bin" folder when you start HTTP(S) Test Script Recorder. The easiest way to get the certificate installed onto mobile device is sending it to yourself by email, opening the email on the mobile device and following system dialog to install the certificate.
References:
HTTPS recording and certificates
JMeter Proxy Step by Step
There is also an alternative solution for recording native and hybrid mobile applications traffic. Using it you won't have to bother about proxies and certificates. As a little bonus, this 3rd-party JMeter Cloud recorder has "SmartJMX" mode with automatic correlations of any dynamic parameters so you won't have to extract them yourself. See How to Cut Your JMeter Scripting Time by 80% guide for details.

Resources