How to read packets on client socket from server socket (in connection oriented (TCP))?

Up vote 0 down vote favorite share g+ share fb share tw.

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...... //code for server socket:- public class ServerConnection implements Runnable { ServerSocket server; Socket client; DataOutputStream dataOut; DataInputStream dataIn; Thread t ; com.equities.

News equitiesNews=new News(); int iMsgNo=0; final int equeitiesNews=1902; public ServerConnection(){ try { 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"); } } public void userLoginReply(){ try { dataOut = new DataOutputStream(new DataOutputStream(client.getOutputStream())); dataOut. Write(equitiesNews.

ConvertToByteStream());//convertToByteStream() to stream is a //method which returns the bytes, to rwite the packet of bytes dataOut.flush(); } catch (IOException e) { System.out. Println("Error in userLoginReply"); } } public void run(){ while(true){ userLoginReply(); } } public static void main(String args){ ServerConnection myserver=new ServerConnection(); } } //code for client socket to read a packet:- help on this code how to read a packet package com; 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; import java.net.

; import java.sql. Connection; import java.sql. ResultSet; import java.util.

ArrayList; import java.util. Calendar; import java.util. GregorianCalendar; import java.io.

; class RequesterClient implements Runnable { Socket client; DataInputStream dataIn; DataOutputStream dataOut; BufferedInputStream bufferIn; BufferedOutputStream bufferOut; Thread t; 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) { } } 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 >>>>>>>: "); int a=dataIn.readInt(); System.out.

Println("value : "+a); System.out. Println("size byte : "+dataIn.available()); //System.out. Println("read data : "+s.length()); } catch (IOException e) { e.printStackTrace(); } } public void run(){ 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) { } java link|improve this question asked Sep 8 '10 at 7:34user44150753 0% accept rate.

If you have more information for a question you've already asked, edit it rather than creating a new one. – Jon Skeet Sep 8 '10 at 7:44.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions