clox: My Latest Invention

This is how clox works.
This is a Language Agnostic Chat Server…..Basically, You should take clox and write any client for it. I have successfully written chat clients for both Desktop and Mobile using clox as the server. This is an effort to simplify writing chat applications. The bulk of the Server side work has been done in clox.
The server is written in java, but you can have clients in any language you want as long they obey these protocols
  1. connect to the server (the port is 1981, make the ip address configurable since the server can be hosted anywhere)
  2. send a message to the server, the format of the message is ”details:port=” + socket.getLocalPort() + “:sname=” + username + “:saddress=” + socket.getLocalAddress() + “\n”; The “:s” is a delimiter that separates the values.
  3. The server then starts sending you messages.
    • If you are just connecting, the server sends you a list of connected clients. The format is “clients:clientName1:sclientName2:sclientName3:setc\n”
    • If you already got the list of connected clients, the server keeps updating this list, so u must continually listen for incoming messages matching this format.
    • Also when someone sends you a message, you get the message in this format ”message:from=sender:s” + “to=recipient:s” + “date=longvalueofdate:s” + “msg=message\n”; The “:s” is a delimiter that separates the values. The date is a long value(System.getCurrentTimeInMillis()).
    • When someone sends you a file, you get it as a stream of bytes.(a byte can easily be casted to an integer). The first thing you recieve is a filename in this format ”file:filename:sport:port\n”. The “:s” is a delimiter that separates the values. This means that the server has opened a new port for you to start sending files. The new port is neccessary so that we dont congest the chat port in case the file is large. Connect to this port and start reading the bytes sent to you. All you need to do is write these bytes directly to the file you created with filename.
  4. When you want to send a message to the another client, use this format
    • “message:from=sender:s” + “to=recipient:s” + “date=longvalueofdate:s” + “msg=message\n”; The “:s” is a delimiter that separates the values. The date is a long value(System.getCurrentTimeInMillis()).
    • When you want to send a file, you do three things
      • send the filename of the file you want to send. The format is ”file:filename=filename:sto=recipient\n”. You must include the name of the recipient in this command.
      • The server then sends you an “ackfile:filename=filename:sport=port\n”. This means the filename has been recieved and the server has opened a port for you to start sending the file as bytes. The new port is neccessary for reasons given in 3d. above.
      • Send the file itself to server (as bytes) through the port opened to you by the server. The server reads the bytes send and reconstruct the file on the other end
  5. Also note that the server will read messages from you until it encounters a new line. So all messages between you and the server must terminate with a newline. The server already observes this when sending messages to you.
  6. The server doesnt take care of duplicate users. Your client application should take care of that. Your client should have a log in of some sort such that only truly registered clients are sent to the server and there are no duplicates.
  7. The server has a gui for management(Starting,stopping and the likes).
  8. I also have a cloxclient project to give you a feel of what the client should look like.
  9. SUPPORTED PROTOCOLS:
    • From Server:
      • clients:csv  see 3a. aboove
      • message:msgstring see 3c. above
      • idle:fromclient, toclient
      • typing:fromclient, toclient
      • sms:fromclient, toclient, smsmessage //not yet implemented
      • file:fromclient, toclient, filename
    • To Server
      • String_clientDetails //this must be send at the point of connection. see 2 above
      • message:string //see 4 above
      • idle:fromclient,toClient
      • typing:fromclient,toClient
      • sms:fromcleint,toClient,smsmessage //not yet implemented
      • file:fromcleint,toClieint,filename

The code is open source, hosted on GITORIOUS, the URL is CloxServer and the desktop client is CloxClient

Happy Cloxing

Comments (2)

Something for Medicine: Drugs Database

There is this project I worked on back in school with a classmate. Its a database of drugs. There is really nothing very spectacular about it, but the java programmers will immediately see how it was created….JAVADOCS.

The way drugs are arranged, it follows a form that can be easily represented by java classes. And that was what we did, after writing the classes, putting in Javadoc comments, we just created the docs, and what we have is this

http://javabuoy.net/drugs/

This is far from a complete job, we have to kinda give up on the idea because both of us started pursuing other fields. But we are kinda coming together again to make this a complete project, with search capabilities and a complete drugs database.

There is nothing wrong with the current lists we, Just that none of them provide it the way we are doing, or better still none of them is taking the Hierarchical approach we are taking.

WIll keep you posted as we go on.

Leave a Comment

NIGERIA!

As some might have guessed from previous posts, I am a nigerian and live in nigeria. This post is however not about that. I just found out today that if you live in Nigeria, you can’t play along with the rest of the world. In fact, it’s as if you don’t exist at all. It all started with online scams, and now the suicide bomb suspect.

As a nigerian, you can’t
1. Register as an Apple Developer to develop iPhone apps
2. Buy anything from Apple.
3. Register on paypal, so you can’t donate(I use free apps a lot and it’s a pain that I can’t donate to them).
4. No paypal, therefore no ebay.
5. Your credit card, even though is valid will be declined by almost everyone on the internet.
6. buy from amazon either.
7. Be a developer and expect funding, no matter how novel your idea is.
8. Have a decent chat on the internet without some1 asking you dumb questions immediately they know you are from nigeria.

grrrrrrrrrrrr……Now I know why guys run-away from this country…..I can’t wait to get the hell outa here!!

Comments (4)

What’s wrong with JavaEE

I actually prefer using Spring and Hibernate. I call it Hibernating in Spring. I have never used JSF, I don’t use JPA, entities are a foreign word(may be alien is better) etc etc. So my knowledge of JavaEE was basically as much as will aid me in Hibernating in Spring.

From JavaEE 5, I decided to read the JavaEE tutorial, I was actually reading it when JavaEE 6 was realeased with Netbeans 6.8. I downloaded both and also downloaded the Java EE Toturial, Volume 1. I read this too. After then I asked myself, what’s wrong with JavaEE?

I mean what’s wrong like why do we need frameworks like struts, wicket, spring, etc etc. The JavaEE stack I believe is matured enough to handle all your needs. I really don’t know how JavaEE was before 5, but since 5, and now 6…..JavaEE is the bomb.

Now we have Facelets – I wonder what can be better than that. JPA, Transactions etc etc. Just for the fact that I hate XML and that the compiler can take care of annotation errors, JavaEE 6 wins. Plus the fact that Netbeans 6.8 has what we can call native support for JavaEE 6. I need someone to convince me that I still need to Hibernate in Spring.

Merry XMas to you all.

Comments (3)

JavaMe Library you might need: Part 2

Following my previous post, I have a new addition to the library. This time its a Date utility. Here is the code

package com.trinisoft.mlib.util;

/**
*
* @author trinisoftinc
*/

public class Date extends java.util.Date {
public boolean isAfter(java.util.Date date) {
if(this.getTime() > date.getTime()) {
return true;
}
return false;
}

public boolean isBefore(java.util.Date date) {
if(this.getTime() < date.getTime()) {
return true;
}
return false;
}

public Date afterSeconds(int secs) {
Date newDate = this;
newDate.setTime(this.getTime() + (secs * 1000));
return newDate;
}

public Date afterMinutes(int mins) {
Date newDate = this;
newDate.setTime(this.getTime() + (mins * 60 * 1000));
return newDate;
}

public Date afterHours(int hours) {
Date newDate = this;
newDate.setTime(this.getTime() + (hours * 60 * 60 * 1000));
return newDate;
}

public Date afterDays(int days) {
Date newDate = this;
newDate.setTime(this.getTime() + (days * 24 * 60 * 60 * 1000));
return newDate;
}

public Date afterWeeks(int weeks) {
Date newDate = this;
newDate.setTime(this.getTime() + (weeks * 7 * 24 * 60 * 60 * 1000));
return newDate;
}
}

Now in your code, say you have a date object, you can do this

dateObject.isBefore(anotherDate);
Date newDate = dateObject.afterHours(24);
........

You can try it out. I also will appreciate suggestions.

Leave a Comment

JavaME Library you might need

I have this javame library I have been compiling for a while. It has a lot of small small code snippets and classes I use often, there is a database part where I have tried as much as possible to encapsulate parts of the saving/retrieving parts of RMS, there is also the UI part, which is what I want to talk about today.

This part contains a TickerForm, which is a form that can show scrollable contents pulled from database or URL at intervals(I am yet to finish it) and the second thing is the Controllable form. This form has a Controller that you can use to service the form(just like posting a form through POST). You call the submit() method of the form and the service method of the controller is called. The service method stores the values of items of the form in a Properties object(which is basically a key-value pair). A code is worth more than a thousand words they say, so here we are

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.trinisoft.atpay.forms;

import com.trinisoft.atpay.MainForm;
import com.trinisoft.atpay.helpers.RecordStores;

import com.trinisoft.mlib.db.decorator.StoreDecorator;
import com.trinisoft.mlib.login.LoginForm;
import com.trinisoft.mlib.login.db.UserClass;
import com.trinisoft.mlib.ui.Form;
import com.trinisoft.mlib.util.Controller;
import com.trinisoft.mlib.util.Properties;

import java.io.IOException;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.TextField;
import javax.microedition.rms.RecordStoreException;

/**
*
* @author trinisoftinc
*/
public class RegisterForm extends Form {

TextField username, password, cpassword;
Command ok, cancel;
LoginForm loginForm;
RecordStores recordStores;
MainForm mainForm;
Display display;

public RegisterForm(LoginForm loginForm, final RecordStores recordStores, MainForm mainForm, Display display) {
super("Register", new Controller() {

public boolean service(Properties properties) {
String username = properties.getParameter("Username").toString();
String password = properties.getParameter("Password").toString();
String cpassword = properties.getParameter("Confirm Password").toString();

if (password.equals(cpassword)) {
UserClass userClass = new UserClass();
userClass.setUsername(username);
userClass.setPassword(password);
try {
new StoreDecorator(userClass).save(recordStores.getUserRecordStore());
properties.setParameter("response-code", new Integer(200));
properties.setParameter("response-text", "Password Mismatch");
} catch (RecordStoreException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
} else {
properties.setParameter("response-code", new Integer(500));
properties.setParameter("response-text", "Password Mismatch");
}
return true;
}
});
this.loginForm = loginForm;
this.recordStores = recordStores;
this.mainForm = mainForm;
this.display = display;
init();
}

private void init() {
username = new TextField("Username", "", 255, TextField.ANY);
password = new TextField("Password", "", 255, TextField.PASSWORD);
cpassword = new TextField("Confirm Password", "", 255, TextField.PASSWORD);
ok = new Command("Submit", Command.OK, 0);
cancel = new Command("Quit", Command.EXIT, 0);

append(username);
append(password);
append(cpassword);
addCommand(ok);
addCommand(cancel);

setCommandListener(new CommandListener() {

public void commandAction(Command c, Displayable d) {
if (c.equals(ok)) {
submit();
if(getResponseCode() == 200) {
display.setCurrent(loginForm);
} else {
Alert l = new Alert("Error Occurred",getResponseText(),null,AlertType.ERROR);
display.setCurrent(l,d);
}
} else if (c.equals(cancel)) {
mainForm.notifyDestroyed();
}
}
});
}
}

You should draw your attention to two places, the contructor and the commandAction in the init() method. In the super constructor, you pass in a Controller, the controller have a service method, which handles the forms submit() and stores response-code and reponse-text keys and values in the Properties passed to it. These keys are used in the commandAction to get the response code and value. Any other value(or object for that matter) that you want to send back as response can be stored in the Properties object.

I think this suite of classes would be useful for anyone interested in Java ME development. Try it out and let me know your feedbacks.

Code hosted at www.gitorious.org/~trinisoftinc

ciao

Leave a Comment

iPhone not Charging.

I have this problem with my iPhone, Whenever I run the battery down to less than 20%, the phone won’t charge again when I plug it in my MAC. But if I plug it in windows it will charge, if and only of the windows box is not been used. If the windows PC is in use, then no charging for iPhone. Of recent, the iPhone started behaving very funny too. Sometimes, the MAC will charge it sometimes it won’t. So I decided to look for reasons why.

First I note that when the battery is below 20%, before you plug it in, shut it down first, then plug it in and everything will be fine. Next, The iPhone will charge if iTunes is not running before you plug it in. If iTunes is running, then you have to close iTunes and open it again, and iPhone is charging. Next I also noticed that most of the electric chargers that ship with the iPhone will not work for you once you jailbreak the iPhone.

The iPhone is a great product, but when people complain about the battery, I think it goes beyond the mere fact that it runs down quickly, the battery of the iPhone is generally shitty, You will be surprised at the vast amount of people who have posted online about this(google is your friend) and yet, apple seems to not want to do anything about it! Although this problem of not charging seems to be experienced by mostly people who jailbroke their iPhones.

Anyway, after about 4hours, today I now know exactly the voodoos I have to invoke to make the iPhone charge anytime anyday anywhere…..I pity the less tech savvy people who use jail broken iPhones.

Comments (1)

Java ME EA on MAC

This is my experience with the JavaME EA for MAC OS. I am using 10.5.8(Leopard).

At first it was a God sent that we now have a tool from sun. Using Netbeans and mpp-sdk kinda sucks, but it was all I have got. After the download, which went without incidents, I ran the EA for the first time and it blew all the whistles and knock all the bells. I immediately opened a sample app and run it, It ran well without incidents. Then out of the blue, I got the first error.

When trying to run ANY application, it will return with an exception/error message that it can not connect to device 0, or any of the devices I used at that. I googled and all the responses were not helping me at all. At last I did the unthinkable, guess what that is? I restarted my MAC. I have not done that in a looooooong while so it took some time before the system actually finished the restarting process and voila, my EA was back online. But not for long!

Next, EA takes it upon itself to just DIE for no reason. I run an app, and the next thing is the EA has stopped working un-expectedly. I also tried googling, but no result. So I started fooling around. I went to tools and refresh the SDK under platforms and voila again, EA stops dying. But again, that was not all.

Next I noticed that after running an app for about 6 to 10 times, EA will stop working saying it has run of memory. I tried to close all applications while running EA but, duh! after about 6 to 10, sometimes 15 runs, it will stop working with the same out of memory error. The annoying thing is, it won’t even quit. I will have to use force quit(windows version of CTRL + ALT + DEL).

I am yet to solve this problem, and I don’t think I will ever solve it until the next version comes out. Looking back however to the days of mpp-sdk and Netbeans, I think I still prefer the EA, At least I can do Bluetooth without having to buy some licence from some people.

All in all, I give Sun +1 on this. It is really something all MAC developers have been asking for since time immemorial. All that remains is perfection. And if I remember correctly, in software, attaining perfection is an eternal process. No software is perfect until it is dead.

One thing I will give kudos to the EA guys for again is that, all projects created on Netbeans also works perfectly on EA, be it from windows or linux. +1 to you guys again on that.

Finally, EA is a good product. If you are a MAC J2ME developer, you will enjoy this IDE.

Comments (4)

Programming VS Movies

When fully charged, My MAC battery lasts for about 5 hours when watching movies. I normally use VLC player and not QuickTime. Last night I checked, when fully charged I can watch three 90mins movies and still have about 20mins or less left on the battery.

But today I was running Netbeans, and when doing so, I also try to run as little applications as possible, just iTunes(I love to code and listen to music), Thunderbird(in case I have any incoming mails), Adium(Although I always put myself in invisible whenever I want to do serious coding), Colloquy(IRC, can I do without it?), and Safari(for javadocs). The apps I dont run when I am coding are Tweetie, Notes, NeoOffice, Preview, TextEdit. Most or all of these are usually opened whenever I am not coding.

So today, I run Netbeans as usual and Firefox. I didn’t run thunderbird, I didn’t run Safari, Adium was not opened, neither is colloquy…I actually wanted to code, and nothing more. To my wildest surprise, from fully charged to empty is a trifle 3hours 40mins(give or take 10mins).

So not only did coding have a high mental effect on humans…causing our minds to run at full speed. It does same to machines too. Maybe its the key presses, or the continous process of building and running and testing and building and testing and runing etc, or what exactly could make coding more battery hungry than watching a movie?.

I wonder.

Comments (6)

Myths, Myths, Myths!

We have moved

J2EE Myths.

I have met a number of java developers who don’t do J2EE. So many of them have so many reasons why they don’t do it. This post is a view at some of these reasons. I call them myths because most of them are actually not true, or not entirely a correct view.

1.J2EE is hard: This is one of the most popular of these myths. The question is J2EE is hard; compared to what? We quickly forget that programming is anything but easy. I started writing Java in 2002/2003. Then I have a number of friends, most of us were VB experts(or addicts depending on who is doing the evaluation). When I deflected and I started learning Java, most of my friends have this same view of J2EE today to Java then. Java is HARD. But today, these guys are .NET/C# Experts, Some have even successfully picked up Functional Languages like erlang. So the thing is, nothing is hard, or difficult. It is our capabilities to handle them that are shallow. The first time I picked up scala, I wrote this post  Scala after one week. Today I know better. So J2EE is not hard. It’s the programmer’s capability to handle it that is not top notch. There are several J2EE projects flying around, the guys that built them are neither aliens, nor programmers on steroids.
2.J2EE is not necessary: This is another myth popular among most especially non-java programmers. Never say something is not necessary until you try it out. J2EE was built to solve a particular problem(I will get to that soon), so unless you say that problem no longer exists, then I can agree with you that J2EE is not necessary.
3.J2EE is too verbose: And so is java. The verbosity of java is not news anymore. I laugh when I see guys compare writing the famous “Hello World” in java to some other languages. The truth is J2EE was not designed to write programs like “Hello World”. It was designed for building multi-tier applications. If what you want to write is “Hello World”, nobody forces you to use J2EE. Some other languages are more suited for that. But to build scalable n-tier applications, then you need J2EE.
4.J2EE is an overkill: Compared to what? Again this is the question I normally ask. Some will say compared to php. It’s pathetic because comparing J2EE to PHP is the best example of Apples and Oranges. I once had a project in PHP (I am almost through converting it to J2EE). After a while, I have to discontinue the project in order to keep my sanity. You can call me a bad PHP programmer, but the truth is in design, PHP was designed so that you can easily write un-maintainable code. It requires extra effort on the part of the developer to write maintainable code. J2EE on the other hand was designed so that it is difficult for you as a programmer to write un-maintainable code. It requires extra effort on the part of the developers to write un-maintainable code. This extra is not an overkill. I write PHP from time to time when all I need is to put together some piece code. But I am sure a very very low percentage of php programmers can be able to build something on the scale of facebook and yahoo using php without running into maintenance issues.
5.J2EE is slow: Your J2EE servers were designed to run on multicore, high end CPUs and not your low end systems. Trying to run Glassfish, for example on a P3 512Mb RAM is suicide. Because what the servers handle are not trivial, so the hardware requirements for them can also not be trivial. For the fact that they can run on low end systems did not mean they should be run on low end systems. If M$ had allowed Vista to run on a P3 512Mb RAM System, imagine what a world this would be!

There are several other reasons people give for not venturing into J2EE, the only valid reason I have gotten over time is I DONT NEED IT NOW. That was the same reason I gave several times over until the need arises. For everyday web-applications, I believe php will just get you by, but you will need J2EE if you are particular about scalability, security, inter-operability, maintainability, and all the other goodies that J2EE have to offer.

Comments (7)

Older Posts »