Openwrt library for REST both client and server - rest

I'm developing an application on openwrt where I need to be able to send HTTP POST's and also receive them. This means I need to be both client and server simultaneously.
The ideia is to support the modes bellow in real time
-> poll mode - where send a POST to a server and process the answer
-> push mode - where I receive a POST from a client and have to send an answer
So far I only found libraries that implement the server or client side but never both. I could use two different libraries to achieve the result I want but it seems a bit "dirty". Here is what I found so far:
-> libcurl - Implements the client side
-> libmicrohttpd - Implements the server side
-> libwebsockets - Implements websockets but I'm not really sure is suited for what I want and needs some further testing
Someone knows a any better suited library? I'm kinda stuck at the moment :)

Not knowing any details of your application I suggest the following. Make a basic and simple solution using:
wget for poll mode
uhttpd for push mode
Write an ash script that glues these two building blocks together. Use cgi-bin to run the script in poll mode.

Related

How do I create bot user with webhook on server side in MongooseIM?

This is what I want
A user(bot) that always shows status Online
When a message comes for the user, I will hit a webhook associated with the user
The response from the webhook request will be sent as reply to the sender
This user will be able to intercept any message (let's say for profanity moderation)
This user will be able to send message to anyone (let's say broadcast)
This user will come in every users roster as default(like echo bot of skype)
I can't seem to find any resource on how to achieve this. I've found a way to intercept the incoming packet in openfire but I don't see any easy way to do this with MongooseIM. I haven't started diving deep into the source code yet, still looking for a way to do this without touching the source code and locking myself to a specific version of MongooseIM.
Disclaimer: I'm on the MongooseIM core team.
There are multiple ways this could be achieved. The easiest way to achieve this depends on your familiarity with Erlang, the programming language MongooseIM is written in.
You won't need any Erlang to use the event pusher module with its HTTP backend and the default settings, but you'd need some Erlang to control what messages get forwarded to the HTTP service or to make more complex setups. To send messages back, you'd either need to use the MongooseIM REST API or connect as an ordinary XMPP client to the server using one of the many XMPP libs available out there. This is probably the best approach to achieve your goal.
You can skip using the event pusher and just connect your bot as an XMPP client written in any language whatsoever. The bot might have your business logic within or can forward messages it gets to the HTTP service.
If you're comfortable working in Erlang, then the mechanism to extend the server is called Hooks and handlers and is described in the official MongooseIM documentation. This requires writing code in Erlang and building from source, but does not necessarily require modifying upstream MongooseIM code.
You could use the XMPP component protocol, which allows to extend the functionality of an XMPP server, yet structure it as multiple services. The components may be written in any technology you want and the most popular XMPP libraries should support the component protocol out of the box.
Depending on your choice from the above list and the language and environment you prefer, you might have to pick an XMPP library to use. There are XMPP libs available for iOS (ObjC and Swift), Android (Java and Kotlin), Python, JavaScript, C, and even some emerging ones for Rust, Dart and possibly more.

best practice to test socket server?

I'm developing a socket server game using java. I want to test if server works properly (how it handles received messages, process and response in right way...) without using game client(heavy and not completed). Messages from client maybe raw binary and encrypted.
Is there a framework, or testing tool for this case?
There are several steps that I take when testing client server systems and mostly I tend to use "normal" unit testing frameworks for this kind of thing, though it only works if you've already designed your code to be unit testable. I also often write a specific stress test client for the server; this can create many thousands of concurrent connections and perform operations on the server and check that it gets the expected results.
For initial server testing you want to have a set of unit tests in place for the key server components; message parsing, etc, and you want to have isolated these components from the code that actually deals with the network (so that you can test it all in a unit test). Push data into the server's message parser and make sure that it parses correctly, and calls the right things, etc.
You can then use your normal unit testing framework to create an instance of your server object (with suitable mocks) which listens on the network and then create a simple client which you instantiate within the unit test and which tests aspects of the server. Often you'll find that there are only a small number of things you actually MUST test like this. Normally connection establishment and termination issues which you want to test with the network as well as independently of it (after all, you can call the connection establishment and disconnection code on your server class from a normal unit test anyway).
Finally you need a custom client which understands your protocol and can put pressure on the server with 1000s of clients - this is the best way to drive out performance and threading issues.
I tend to work on all of these things from the very start; see this blog post for more details.
If you want to do it by hand, I would suggest telnet or, if you're using Linux, you can use netcat command nc.
If you want something that can be automated, e.g. a unit test, and you're familiar with Python, I would recommend using Twisted: Twisted Examples
Hope this helps

Simulating Virtual Users for Smartphone App based Service

Apologies if something similar has been asked in the future but my search didn't return, what I would consider, directly related.
I am trying to implement a service with its backend in AWS EC2/S3 and front-end in iPhone and the service is more or less like a todo-list. This is not a novel idea but will help me in a class I teach about IT infrastructure.
Unfortunately I have access to only my own iPhone and I cannot demonstrate scalability over AWS, etc.
Is there a way/software tool/framework to simulate virtual users for this app that can send requests to the AWS servers pretending to be from different accounts/apps?
The simulator should send requests just like my actual iphone app would send if I were to add an item to the list or delete or edit.
I understand stress testing is a well established topic but here I want to just simulate multiple users and demonstrate scalability instead of trying to push the Web service to its limits. Neither am I sure if this completely overlaps with traffic simulation.
Any help will be deeply appreciated.
You might be able to do it using Apache JMeter. That depends on what you have going on on the backend. But it supports the following server types:
Web - HTTP, HTTPS
SOAP
Database via JDBC
LDAP
JMS
Mail - SMTP(S), POP3(S) and IMAP(S)
Native commands or shell scripts
You should be able to wire something together with that.
http://jmeter.apache.org/
http://www.opensourcetesting.org/performance.php
I've used it at various points to simulate VERY heavy loads for my services running in AWS/EC2.
Apache Benchmark is a very convenient tool for doing HTTP load testing -- you can have it make concurrent requests to simulate multiple users. It's main advantage over other tools is that it's simple and easy to get started with. If your backend listens on HTTP, it might be worth trying ab before investing any time in something more complex.

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#?

Mechanism for Server Push with Apache and Perl

I'm looking to add some sort of HTTP push-like functionality, implemented via long polling or another standard means, to a page built with Perl on top of Apache.
Is there a way to do this without setting up a separate server such as Meteor or Stardust? Is there a module that would help with the server code? Is there a way other than long polling?
If your need a quick and dirty fix to avoid major changes to your current application or design, and you do not need instant updates, then one simple approach is to use regular AJAX polling from the browser to the server.
In other words you would have javascript in your browser check the server every couple of seconds to see if there is any message and/or data on the server for this browser session. This will most likely not scale very well, especially with short poll timeouts, and will eat up server resources, but it may be a useful stopgap solution.
Just to reiterate, this is just a quick fix workaround - general consensus is you need to use COMET (probably on a separate server in your case) as a proper solution (until websockets arrive...) - see some good analysis in these links:
http://cometdaily.com/2007/11/06/comet-is-always-better-than-polling/
http://stackoverflow.com/questions/2975290/comet-vs-ajax-polling