the last few weeks were a bit boring about Google Wave and I developed with java.net on my home network to show how powerful java actually is.
What did you exactly do?
At first I implemented a server with a serversocket which is listening to a certain port and awaiting a connection from a client. It was just a basic i/o chat with some in- and outputstreams. That was quite easy so I decided to add more functionality to my application.
The first thing I added was a multithreaded server, you know: It awaits a connection with a while(true) loop and then it starts a thread with the i/o stuff. That is the best solution if multiple clients will connect.
Basically I was a bit disappointed that you could only send textmessages from a client to a server, but then I read about sending images. So I wrote a client class which opens a socket to the server and pulls an bytearray out of the image. Then this array is send to the server via a stream and on the serverside I did the same vice versa.
There were several problems:
- The server didn't know whether the stream was text or image
- There is a need of two GUIs server / client, minimizeable to tray
So the issue is to devide between a text and an image. I had some ideas of setting a "type" byte in the bytearray, but then I made two sockets with two different ports and made the server listen to both in two threads.
With that improvement it is possible to send text and image at the same time.
The diagram of the classes in BlueJ looks like that:
What you see here is the architecture of the Client and Server. The Client starts in the StartUp's class main function, then the GUI will be created and the fileDrop manages the Drag&Drop events on the GUI. When the send button is pressed a new object of clientText will be created, this is an inheritance of ClientImage and provides an own socket just with another outputstream than the clientimage. Besides the streams the image is turned into bytearray whereas the text is just a string.
The TextTransfer class manages the copy to clipboard ability on the server.
So the main usecase of this application is when I am sitting on my desktop and another one is sitting anywhere else (but he must be in my local area network) in the house, I can communicate with him.
The next steps I would like to do:
- Adding a "server search", my DHCP gives new addresses all the time so I had to compile the source with a new IP
- Get Client and Server together, like a PeerToPeer chat client.
So we all saw, what we could do with a little bunch of code, we implemented Threads, we parallelized, we created GUI's and we had developed with TCP/IP protocol and sockets. And the best is, we can run the code in a *.jar file on every operating system on the world, just if java is supported.
In my own network I run it from Windows XP to 7 and from Debian lenny to Ubuntu karmic.
Here is the sourceforge link: https://sourceforge.net/projects/lanchatter/
I hope GoogleWaves new API will be deployed soon, I am dying of boredom =/
Have a nice day forum!
Keine Kommentare:
Kommentar veröffentlichen