java p2p without any framework
<p>I need to develop a p2p application that DOES NOT use any framework like JXTA. I searched through various topics in StackOverflow but I am not getting what I want.  I have a server that maintains the list of clients and its resources. The clients will contact the server to find out which client has what. After the client gets this info from the server, it will establish a p2p connection with the other client - the server is not involved in this. </p>

<p>I need to know as to how to create a client socket and a server socket in the same program i.e the program should like a server and client. Please help me out. </p>

<pre><code>for ex:
 client code 
 Socket clientSocket = new Socket("localhost", 10000);

 server code
 ServerSocket welcomeSocket = new ServerSocket(10000);

     while(true)
     {
        //client socket
        Socket connectionSocket = welcomeSocket.accept();
        .......
        .......
     }
</code></pre>

<p>How will I add a serversocket to my client and make it work like a server? I know I have to use threads, but can anyone explain this in detail? or please post a RELEVANT thread.. I am tired of looking through various forums and websites.. </p>
