Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- socketChannel = SocketChannel.open(destNode);
- objectOutputStream = new ObjectOutputStream(Channels.newOutputStream(socketChannel));
- objectInputStream = new ObjectInputStream(Channels.newInputStream(socketChannel));
- Thread replyThread = new Thread("SendRunnable-ReplyThread") {
- @Override
- public void run() {
- try {
- byte reply = objectInputStream.readByte();//(A)
- //..process reply
- } catch (Throwable e) {
- logger.warn("Problem reading receive reply.", e);
- }
- }
- };
- replyThread.start();
- objectOutputStream.writeObject(someObject);//(B)
- //..more writing
- Socket socket = new Socket();
- socket.connect(destNode);
- final OutputStream outputStream = socket.getOutputStream();
- objectOutputStream = new ObjectOutputStream(outputStream);
- objectInputStream = new ObjectInputStream(socket.getInputStream());
- public InputStream getInputStream() throws IOException {
- return Channels.newInputStream(new ReadableByteChannel() {
- public int read(ByteBuffer dst) throws IOException {
- return socketChannel.read(dst);
- }
- public void close() throws IOException {
- socketChannel.close();
- }
- public boolean isOpen() {
- return socketChannel.isOpen();
- }
- });
- }
- public OutputStream getOutputStream() throws IOException {
- return Channels.newOutputStream(socketChannel);
- }
Add Comment
Please, Sign In to add comment