Perseverance and a nice win

I’ve already got the media manager software completed, although it will get a huge face lift in the near future. I’ve also got a running server that at the moment does quite a lot of things. I’ve also got the player on the devices making solid connections. New devices show up in the file system and internal databases. All the servers responses are currently 100%.

Tonight, I got my android app communicating with the server. After a silly mistake, the app now fetches new devices from the server and displays them ready for the next step. All connections are completely over the internet and via TCP. Eventually, once all test have been completed, all the security will be put into place. I’m not even thinking about security just yet because the later I leave it before the final product, the more secure it will be.

Actually, that very last sentence has just got me thinking about security. I seriously need to start securing this right now. Tomorrow I will implement the initial security layer (which is configurable).

Still no code snippets, sorry.

And still a fair bit of work to get done.

20 GO TO 10

Personal project update Wed 20/09/17

The player software I am writing which had a big refactor last night now sends its unique ID to the server. The server also now stores this without a playlist which can be picked up by the mobile application which I started last week, but tomorrow I will work on.

At the moment, the server does actually look through the internal database and responds to the client, which is working so far. At the moment it just responds with a zero playlist and closes the connection.

I was too busy to be adding the encryption which can actually wait for now.

The next step is to get the Android software to be able to create temporary playlists, pick up empty devices, duplicate other devices playlists and set a new device up. Just this bit will take a little while because the Android API is quite huge and I’m used to using Qt, not Android Studio.

What I ought to be doing, which is what I do at work, is to keep a progress diary. I’ll make a start on that now actually. This I can update every time I work on my own projects.

I’m happy with the progress so far because even though I get a maximum of 2 hours after work and maybe a little bit more at the weekends, this particular project is taking shape finally.

There will be one main PC piece of software that will control everything as well as a few Android apps that do their bits. The devices player and the server are the easy bits. Although through time, I’ll have to look at making this scalable.

Project update (no code snippets tonight)

My personal project has taken a huge face lift. The original player code has been stripped and split into two classes, the media client layer and the player itself.

The media client is the heart of the player which handles the communication with the server and supplies the player with its playlist. It’s still not compete by far, but closer to what I need it to do.

The player at the moment does zip all. The intention is to have it playing a media file and then check with the media client of any updates which will adjust it’s playlist. All previous tests of the media player have been running great.

The android app is still waiting on the above media client and its communication with the server so that I can move that one forward.

Basically tonight has been refactoring a lot of code. With a lot of testing in between. So far so good, but I’ve run out of time for tonight. Two hours isn’t enough.

I’ll need some time to do some Blender work soon also.

Cryptography Secure TCP Sockets in Java

Well, I finally got round to testing out a basic encryption over TCP sockets.

First off, the main() entry looks very familiar and is easy to understand. I simply create the listening server (doesn’t spawn thread for simplicity), with the ability to safely shut it down.

Then I use the DataInputStream and DataOutputStream to send data back and forth. In this test case I sent a string which both the client and server will print to the console.

Once that was working, I extended the OutputStream and InputStream and override the read() and write() methods (shown in the code examples below). Notice that I manipulate the byte in two different ways, one by adding and subtracting and the other by XOR’ing (commented out but works). If these manipulations match up whilst data is being sent back and forth then there’s no errors.

Main class

The main class and entry point to the test which spawns the server and then runs a couple of tests:

package com.wlgfx.cryptotest;

public class CryptoServer {

    public static void main(String[] args) {
        WLCryptoServer server_run = new WLCryptoServer();
        Thread server = new Thread(server_run);
        System.out.println("Server thread started");
        new Thread(new WLCryptoClient("Hello world!")).start();
        try { Thread.sleep(500); } catch (InterruptedException ex) {}
        new Thread(new WLCryptoClient("Jump around and stomp your feet!")).start();
        try { Thread.sleep(500); } catch (InterruptedException ex) {}

Server class

The server code which take the input and output streams and creates new subclasses of the encryption layer classes and then creates the usual DataInputStream and DataOutputStream for the rest of the normal IO. This matched in the following code for the client.

package com.wlgfx.cryptotest;

import com.wlgfx.cryptotest.WLC.WLInputStream;
import com.wlgfx.cryptotest.WLC.WLOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class WLCryptoServer implements Runnable {
    private final int port = 1999;
    private boolean quit = false;

    public void run() {
        try {
            ServerSocket socket =  new ServerSocket(port);
            while (!quit) {
                Socket client = socket.accept();
                WLOutputStream wlout = new WLOutputStream(client.getOutputStream());
                DataOutputStream out = new DataOutputStream(wlout);
                WLInputStream wlin = new WLInputStream(client.getInputStream());
                DataInputStream in = new DataInputStream(wlin);
                String text = in.readUTF();
                System.out.println("SERVER: " + text);
        } catch (IOException ex) {
            System.out.println("SERVER: " + ex.getLocalizedMessage());
    public void quitServer() {
        quit = true;

Client class

The client code is just the same as the server class code.

package com.wlgfx.cryptotest;

import com.wlgfx.cryptotest.WLC.WLInputStream;
import com.wlgfx.cryptotest.WLC.WLOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;

public class WLCryptoClient implements Runnable {
    private String text;
    private Socket socket;
    private final int port = 1999;
    public WLCryptoClient(String test) {
        text = test;
    public void run() {
        try {
            socket = new Socket("localhost", port);
            WLOutputStream wlout = new WLOutputStream(socket.getOutputStream());
            DataOutputStream out = new DataOutputStream(wlout);
            WLInputStream wlin = new WLInputStream(socket.getInputStream());
            DataInputStream in = new DataInputStream(wlin);
            text = in.readUTF();
            System.out.println("CLIENT: " + text);
        } catch (IOException ex) {
            System.out.println("CLIENT: " + ex.getLocalizedMessage());

The encryption class

This is where you can see exactly how easy it is to manipulate the data being sent back and forth.  Here I am showing you two methods, XOR and add and subtract. It’s very simple, but for heavier encryption you could look further at CSPRNG, or Crypto Secure Pseudo Random Number Generator. PRNG’s are ten a penny, from simple ones to hefty things. Take your pick. The Crypto and Secure layers are the ones you really need for truly undecipherable data communication.

package com.wlgfx.cryptotest;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class WLC {

    // NB: short inner classes are static to avoid errors
    public static class WLInputStream extends InputStream {

        private InputStream in;

        public WLInputStream(InputStream input) {
            in = input;

        public int read() throws IOException {
            byte a = (byte) in.read();
            return (int) a;

            //return in.read() ^ 255; // WORKS TOO

    public static class WLOutputStream extends OutputStream {

        private OutputStream out;

        public WLOutputStream(OutputStream output) {
            out = output;

        public void write(int b) throws IOException {
            byte a = (byte) b;
            out.write((int) a);

            //out.write(b ^ 255); // WORKS TOO
Console output:
Server thread started
SERVER: Hello world!
CLIENT: Hello world!
SERVER: Jump around and stomp your feet!
CLIENT: Jump around and stomp your feet!
SERVER: Accept timed out
BUILD SUCCESSFUL (total time: 1 second)

Until next time


A weekend of zero coding

Nope, not an ounce of coding.

I needed a break.

I was feeling burnt out.

Not even a ride on my motorbike because of bad guts.

And I’m not even thinking about coding tonight before I go bed because this chilled out weekend seems to have done some good for me.

Not really an update…

Another week done and a few wins at work. I’ve been writing code to display graphics for statistical data. ie. Sales targets and stuff. Most of the awkward stuff was having to accommodate for different resolutions, portrait and landscape modes and also having to calculate the font metrics. All done though although I do need to make a few adjustments to get the advanced settings to work properly.

My personal project has gone on hold until this weekend (tomorrow), because  two hours on an evening is not enough time to get stuck in to it. I need thinking time more than I need coding time. And then I need debugging time.

I have noticed though over this past year, I can write a shed load of code, a good few hundred to over a thousand lines of code, before I can finally test it out and it works. Well, saying it works, it’s easier to fix the bugs when it finally comes to testing.

This weekend I want to test communication over the internet using a crypto secure pseudo random number generator, or CSPRNG. Basically the client and server socket connections will be able to communicate without the transmitted data being viewed by any outsiders. The technique is quite simple, it’s the implementation of it and how it is handled that needs to be secured. Other systems use private keys, hashes, passwords, etc. A long list of security protocols. I kind of like the two stage authentication. Because this will be running through four pieces of software, I’ve devised a two way security system. Only access is allowed from the outside from my PC (if that is my work station) or my phone. And then, if this takes off, text message stage too. It boils down to a ‘real’ MAC address and the ‘fake’ MAC address. TCP communications can hopefully solve this by authenticating a number of things.

Anyway… I’m tired. Beers are knocking me out, and as usual, not my brain cell. So good night…

PS. Any up-scaling in the future I’ve made a few mental notes.

My own website

For my own website I do not need SEO. Those who view it have come through searches or from my own online profiles. There’s absolutely no need for me to up views on my pages because I class this as a personal blog/diary and therefor I’m not wanting to advertise myself to the world or other outlets. Simple really.

My other website is for that and I’ve already got it covered.

Now back to some coding.

I have been busy actually

Saturday and Sunday I was faffing about with my Odroid U3 trying to get various API’s to play full screen videos on Linux but kept coming up against a brick wall because those API’s are for openGL and not openGL ES. Only Android would do that and I do not want to go down that route. So instead of buying the Odroid C2 which was my original plan I’ve ordered myself an Intel board instead. Can’t wait for it to turn up. The weekend dragged with all the testing and testing.

Tonight I decided to get a spreadsheet together. Being on the extremes of pessimism, the figures still look damn good. It’s given me a positive frame of mind to move on. I will be expanding on the spreadsheet a hell of a lot as this is the first set of figures I’ve started to work with. I plan on getting a full set of test data to start with to get the numbers down to the penny. I’ve still got to price up servers, etc.

Then I got another quick blast at blender. Two things I wanted to get working, alpha transparency for PNG images and playing a video clip in a texture. Yes, I can do them both. And boy, it’s looks good as a 3D rendered movie with transparent images and movie clips playing.

Fullscreen video playlist done

Using Linux and libvlc I’ve finally got what I was aiming for. A full screen video playlist player. And it was quite easy.

The steps to get here:

  1. Monday: Play a media file. A few lines of code did this. And with the addition of one extra line of code made it full screen.
  2. Play a playlist of videos full screen. This is where things went wrong. After one video had finished, the vlc player would quit fullscreen, flash the desktop and then play the next video in full screen. This was not acceptable.
  3. Tuesday: Using the stock Linux libraries to go full screen. This took all of about 20 minutes from start to end. And again, in just a few lines of code. It was a chaotic night at home so I just finished up there.
  4. Wednesday: Just chilled out and watched TV after work instead.
  5. Thursday: I now needed to use the full screen window and attach the videos to it so that the desktop doesn’t appear. By just passing the window ID to the vlc media player, this was done.

Now all I need to work on the managing the playlists over the internet. And order myself and Odroid C2 with a few other gadgets. So far, this is going 100% perfectly.

By my reckoning, I should have a media player that boots up in less than 10 seconds and playing. How awesome…

The hefty part of the coding is about to start…

Having a wind down for the holiday away.

It’s Monday evening now and on Wednesday, my loved one and I are jetting off to Morroco for a break away and much deserved to get away from reality.

However, I’ve already setup a laptop that I’m taking with me for when I get heat stroke, or something else like boredom, for not only keeping in touch with family and friends (when we’re not busy lazying it), with a small ssd. My accounts are not being stored on it just in case but I have installed some essential IDE’s that I use.

When I get back, and as I’ve already setup, I’ve got a test home server running which I can monitor and use while I’m away. A few final touches to it tomorrow evening. With the wifi at the hotel, I’m going to knock up a quick android app to test it out with.

Apart from that, I’m pretty grumpy at the moment. Home is a tip and needs a hand-grenade throwing at it. Worrying about the next week while we’re away. Argh!!!

Anyway… Noisy all of a sudden here…