Please edit your post and wrap your code with
to get highlighting and preserve formatting.

Could you explain how your application works? The posted code doesn't have any comments that describe what it does. Where is the -1 displayed?

Is there a way to test the code without a server? Do you have a testing driver?