Project P2P Library
28 Jan 2008
A good library for developing Peer-To-Peer applications is being developed by me and a friend. The aim is to enable ease of development of a Peer to Peer System. For now, you can write a peer as
public class MyOwnPeer extends Peer
{
//implement few methods!
}
The peers identify each other through IP Multicasting. In a day or two, I hope to write a short tutorial on how to develop a P2P chat application using our library. For now, it runs within private networks only. And does not run across internet!
Also the library at its current stage enables very easy development of Server application! you can write your echo server without having to worry about threading or anything else!
It is as simple as
public class EchoServer extends ServerComponent
{
//implement few methods!
}
We hope to release the library as early as possible.
The echo server sample is shown below!
Isnt' that easy! This is just the very initial stages of development and hopefully the library grows to something really big. The library relies heavily on Object-Oriented Concepts !
// SAMPLE SERVER CODE!!
class EchoServer extends ServerComponent {
public EchoServer(int port) {
super(port);
}
@Override
public void beforeServerStarts() {
System.out.println("Server about to start");
}
@Override
public void onIncomingConnection(Socket socket) {
try {
BufferedReader buff = new BufferedReader(new InputStreamReader(
socket.getInputStream()));
PrintWriter pw = new PrintWriter(socket.getOutputStream());
String temp = "";
while ((temp = buff.readLine()) != null) {
pw.println(temp);
pw.flush();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void onServerStarted() {
System.out.println("Server Started!");
}
public static void main(String[] args) {
EchoServer my = new EchoServer(1233);
}
}