2
* JBoss, Home of Professional Open Source
3
* Copyright 2005, JBoss Inc., and individual contributors as indicated
4
* by the @authors tag. See the copyright.txt in the distribution for a
5
* full listing of individual contributors.
7
* This is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU Lesser General Public License as
9
* published by the Free Software Foundation; either version 2.1 of
10
* the License, or (at your option) any later version.
12
* This software is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this software; if not, write to the Free
19
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23
package org.jboss.test.remoting.transport.socket.raw;
25
//import org.jboss.remoting.transport.socket.OptimizedObjectInputStream;
26
//import org.jboss.remoting.transport.socket.OptimizedObjectOutputStream;
28
import java.io.BufferedInputStream;
29
import java.io.BufferedOutputStream;
30
import java.io.IOException;
31
import java.io.ObjectInputStream;
32
import java.io.ObjectOutputStream;
33
import java.net.InetAddress;
34
import java.net.ServerSocket;
35
import java.net.Socket;
38
* @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
40
public class RawServer implements Runnable
42
protected int serverBindPort = 6700;
43
protected int backlog = 200;
44
protected ServerSocket serverSocket;
45
protected InetAddress bindAddress;
46
protected String serverBindAddress = "localhost";
47
protected int timeout = 60000; // 60 seconds.
53
bindAddress = InetAddress.getByName(serverBindAddress);
54
serverSocket = new ServerSocket(serverBindPort, backlog, bindAddress);
62
public void startServer()
64
new Thread(this).start();
68
* When an object implementing interface <code>Runnable</code> is used
69
* to create a thread, starting the thread causes the object's
70
* <code>run</code> method to be called in that separately executing
73
* The general contract of the method <code>run</code> is that it may
74
* take any action whatsoever.
82
Socket socket = serverSocket.accept();
83
socket.setSoTimeout(timeout);
85
BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream());
86
// OptimizedObjectOutputStream out = new OptimizedObjectOutputStream(bos);
88
BufferedInputStream bis = new BufferedInputStream(socket.getInputStream());
89
// OptimizedObjectInputStream in = new OptimizedObjectInputStream(bis);
91
ObjectOutputStream oos = new ObjectOutputStream(bos);
93
ObjectInputStream objInputStream = new ObjectInputStream(bis);
96
processRequest(objInputStream, oos);
100
acknowledge(objInputStream, oos);
101
processRequest(objInputStream, oos);
110
catch(ClassNotFoundException e)
116
private void processRequest(ObjectInputStream objInputStream, ObjectOutputStream oos)
117
throws IOException, ClassNotFoundException
119
Object obj = objInputStream.readObject();
120
objInputStream.readObject();
122
// Object obj = in.readObject();
123
// in.readObject(); // for stupid ObjectInputStream reset
125
System.out.println("Object read: " + obj);
130
// Make absolutely sure thread interrupted is cleared.
131
boolean interrupted = Thread.interrupted();
132
// call transport on the subclass, get the result to handback
133
resp = "This is response.";
140
Thread.interrupted(); // clear interrupted state so we don't fail on socket writes
143
oos.writeObject(resp);
148
// to make sure stream gets reset
149
// Stupid ObjectInputStream holds object graph
150
// can only be set by the client/server sending a TC_RESET
151
oos.writeObject(Boolean.TRUE);
156
private void acknowledge(ObjectInputStream objInputStream, ObjectOutputStream oos) throws IOException
158
// now stay open and wait for ack
159
System.out.println("waiting for ack");
160
byte ACK = objInputStream.readByte();
161
System.out.println("got ack");
168
public static void main(String[] args)
170
RawServer server = new RawServer();
171
server.startServer();
b'\\ No newline at end of file'