Archive

Monthly Archives: November 2011

For new multiplayer social game I created simple TCP client as Android application. It connects to special echo server (.NET) and sends/receives packets to/from other clients. Packets are UTF-8 text messages prefixed by string length 4-bytes integer as a header of the packet.

Android-tcp-client

I used Java NIO to implement network layer with second worker thread to wait for connection establishment and further reading of incoming packets. Network layer is separated of GUI, so, ready to be used in other Android application. Eclipse project, .NET server and client for tests are here.

 

Luxoft started some special compaign to find/hire more developers.
Here they put small exercise to catch attention of software developers.
The task is to decode ascii text provided as binary string.
There is my implementation by ruby and decoded text:

## If you are reading this message you definitely know what binary code is about.# Take a chance and win a certificate for free training-course at Luxoft Training to upgrade your skills in the IT subject you are interested in#bin_code = "010010010110011000100000011110010110111101110101001000000110000101110010011001010010000001110010011001010110000101100100011010010110111001100111001000000111010001101000011010010111001100100000011011010110010101110011011100110110000101100111011001010010000001111001011011110111010100100000011001000110010101100110011010010110111001101001011101000110010101101100011110010010000001101011011011100110111101110111001000000111011101101000011000010111010000100000011000100110100101101110011000010111001001111001001000000110001101101111011001000110010100100000011010010111001100100000011000010110001001101111011101010111010000101110000011010000101001010100011000010110101101100101001000000110000100100000011000110110100001100001011011100110001101100101001000000110000101101110011001000010000001110111011010010110111000100000011000010010000001100011011001010111001001110100011010010110011001101001011000110110000101110100011001010010000001100110011011110111001000100000011001100111001001100101011001010010000001110100011100100110000101101001011011100110100101101110011001110010110101100011011011110111010101110010011100110110010100100000011000010111010000100000010011000111010101111000011011110110011001110100001000000101010001110010011000010110100101101110011010010110111001100111001000000111010001101111001000000111010101110000011001110111001001100001011001000110010100100000011110010110111101110101011100100010000001110011011010110110100101101100011011000111001100100000011010010110111000100000011101000110100001100101001000000100100101010100001000000111001101110101011000100110101001100101011000110111010000100000011110010110111101110101001000000110000101110010011001010010000001101001011011100111010001100101011100100110010101110011011101000110010101100100001000000110100101101110"n = bin_code.length / 80.upto(n-1) { |i|    s = bin_code[i*8...(i+1)*8]    print s.to_i(2).chr}

I was involved into discussion about 2 ways of C/C++ windows application project: split the project into DLL vs. static linking or even compiling from sources. One of the opinions was to use DLL’s as default and best development/runtime structure.

I disagree with such point of view. From my 10+ years of successful C/C++ programming experience it would be better to use static linking or even compile the code from source.

  1. It would be better to avoid DLL’s because of potential ‘DLL hell’ problem.
  2. If you compile from sources then you have ability to provide changes and compiler optimization if you need.
  3. Less files as project build would be easy to support.

Of course, there would be reasons to use DLL’s as well, like, plugin’s pattern, multi-language development or some kind of separation in the development process, e.g., component model or to crypt/protect the code. But (one more time) by default it would be better to avoid using DLL’s.

I’ve been used Gmail as primary email tool for already several years. I started using new UI last week.
It’s even more useful for now. I turn on simple theme without drawings and other things I really don’t care.

Also, I turned on keyboard shortcuts. On my macbook without mouse it’s really helpful:

  • j, k  —  next, prev. like in good old vi
  • x — mark the message
  • # (Shift-3) — delete the message
  • Enter — open the message

Today I’m working on TCP/IP socket client module for android java application.
There are 2 threads: worker thread to receive messages from server and initial UI thread.
Unfortunately, it’s impossible to change UI elements from a non-UI thread.
I use android.os.Handler to send some message from non-UI (worker) thread to UI.

import android.os.Handler;

private Handler _handler;

// in UI thread
_handler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
        // process message from worker thread
        if(msg.what == ADD_MESSAGE) {
            _addMessage((String) msg.obj);
        }
        super.handleMessage(msg);
    }
};

// send message from worker thread to UI
Message msg = EchoClientActivity.this._handler.obtainMessage();
msg.what = ADD_MESSAGE;
msg.obj = message;
EchoClientActivity.this._handler.sendMessage(msg);