views:

80

answers:

1

hello, i m a new . i m a java developer(fresher) and currently i m working on BSE project and i m facing problem to read the packet of bytes on the client(client socket) from the server(server socket). if u can help me then please help me.

Thanks in advance

+1  A: 

Well, if you want to interact directly with packets, then you need to use a DatagramSocket instead of the regular Socket and ServerSocket.

Then, you should visit this link to see a good tutorial on how to get started with sending and receiving individual packets.

The basic idea is that the Client or Server will block on the recieve() call while it waits for its partner to send a packet using send().

If you aren't interested in the individual packets like you indicated in your question, then you will want to use Socket and ServerSocket. The first step to communicating between the two involves code that will look similar to the following:

//Server
// this call will block until the client tries to connect to the server
Socket cientConn = new ServerSocket(8878).accept();
// now you can use the connection's input and output streams to send data

/******************/

// Client
Socket serverConn = new Socket(addressOfServer, 8878);
// now you can use the connections input and output streams

After you get connections set up, you will have basically 2 read/write loops. One on the client, and one on the server.

while(true) [
    // check for data from an input stream
    ...
    // respond with message back
}

You will need a similar loop for the client and the server.

jjnguy
thanks, 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 socket and server socket.
i m creating connection oriented server(TCP).
thanks, 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 socket and server socket.
i mentioned code here check it n then help me
@deepak, Your question is too vague. I have updated my answer with a little more information, but could you please update your question with some more information?
jjnguy