How to read packets on client socket from server socket (in connection oriented (TCP))
<p>i m creating connection oriented server/client(TCP) socket.i have created whole server socket and i have written packet on server socket successfully and i have created client socket also but i m not be able to read packet so please give me the idea about read the packet(code or example) on client socket and tell clearly that can i read a packet on client socket or not if no then what should use in place of client and server socket. i m putting the code both server/client socket......</p>

<p>//code for server socket:-
public class ServerConnection implements Runnable 
{
  ServerSocket server;
  Socket client;
  DataOutputStream dataOut;
  DataInputStream dataIn;</p>

<p>Thread t ;</p>

<p>com.equities.News equitiesNews=new News();</p>

<p>int iMsgNo=0; 
  final int equeitiesNews=1902;
  public  ServerConnection(){
    try {</p>

<pre><code>  server=new ServerSocket(6100);
  System.out.println("Server Is Started...");
  while(true){
   client=server.accept();
   System.out.println("socket accepted :"+client);
   t= new Thread(this);
   t.start();
   System.out.println("Server Socket is created");
  }
} catch (Exception e) {
 e.printStackTrace();
   System.out.println("Errrrrrrrrrrrrrorrrrrr");
}
</code></pre>

<p>}</p>

<p>public void userLoginReply(){</p>

<p>try {
   dataOut = new DataOutputStream(new DataOutputStream(client.getOutputStream()));</p>

<p>dataOut.write(equitiesNews.convertToByteStream());//convertToByteStream() to stream is a //method which returns the bytes, to rwite the packet of bytes</p>

<p>dataOut.flush();
  }</p>

<p>catch (IOException e) {
  System.out.println("Error in userLoginReply");
 }
 }</p>

<p>public void run(){
  while(true){
  userLoginReply();
  }
  }
  public  static  void main(String args[]){</p>

<pre><code>  ServerConnection myserver=new ServerConnection();
</code></pre>

<p>}
} </p>

<p>//code for client socket to read a packet:- help on this code how to read a packet</p>

<p>package com;</p>

<p>import java.beans.Statement;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;
import java.net.UnknownHostException;</p>

<p>import java.net.<em>;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.io.</em>;
class RequesterClient  implements Runnable
{</p>

<p>Socket client;
 DataInputStream dataIn;
 DataOutputStream dataOut;
 BufferedInputStream bufferIn;
 BufferedOutputStream bufferOut;</p>

<p>Thread t;</p>

<p>public  RequesterClient(){
      try {
        System.out.println("Socket is created");
        client=new Socket();
        client.connect(new InetSocketAddress("192.168.0.115",6100));
        t=new Thread(this);
        t.start();
       } catch (Exception e) {
       }
    }</p>

<pre><code>public void reciveNewsData(){
 try {
   bufferIn=new BufferedInputStream(client.getInputStream());
   dataIn=new DataInputStream(bufferIn);

   BufferedReader br=new BufferedReader(new InputStreamReader(client.getInputStream()));

   //byte b[]=br.toString().getBytes();
   //byteIn=new ByteArrayInputStream(b);
   //System.out.println("size byteIn : "+br.ready());
   //System.out.println("size dataIn : ");
   //byte b[]=;
   //System.out.println("size dataIn &gt;&gt;&gt;&gt;&gt;&gt;&gt;: ");

   int a=dataIn.readInt();

   System.out.println("value : "+a);
   System.out.println("size byte : "+dataIn.available());

   //System.out.println("read data : "+s.length());
</code></pre>

<p>} catch (IOException e) {
   e.printStackTrace();
  }
    }
    public void run(){</p>

<pre><code>      try {
       System.out.println("before method");
       while(true){

       reciveNewsData();
          }

      } catch (Exception e) {
           e.printStackTrace();
      }

       System.out.println("client read");

     }


public static void main(String ar[])
{   
</code></pre>

<p>}</p>
