import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.spdy.IStream;
import org.eclipse.jetty.spdy.SPDYServerConnector;
import org.eclipse.jetty.spdy.api.DataInfo;
import org.eclipse.jetty.spdy.api.ReplyInfo;
import org.eclipse.jetty.spdy.api.Stream;
import org.eclipse.jetty.spdy.api.StreamFrameListener;
import org.eclipse.jetty.spdy.api.StringDataInfo;
import org.eclipse.jetty.spdy.api.SynInfo;
import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener;
/**
* Server.<br/>
* Note: Put
* <code>-Xbootclasspath/p:lib/spdy/npn-boot-7.6.2.v20120308.jar</code> as
* vmarg.
*/
public class BugTestServer {
public static void main(final String[] args) throws Exception {
// Frame listener that handles the communication over speedy
ServerSessionFrameListener frameListener = new ServerSessionFrameListener.Adapter() {
@Override
public StreamFrameListener onSyn(final Stream stream,
final SynInfo synInfo) {
// Send a reply to this message
try {
stream.reply(new ReplyInfo(false)).get();
} catch (Exception e) {
System.err.println(e.toString());
}
// start new message sender thread
Runnable task = new Runnable() {
public void run() {
while (true) {
try {
IStream s = (IStream) stream;
System.out.println(s.getWindowSize());
// FIXME : Here is the problem, the client updates the
// window size down from 64K to 300 then 100 then 56 and
// even 0 bytes, the server then truncates data frames,
// check whether this is legal according to the spec
// TODO : a workaround for us is to have a terminator
// (e.g. checksum) in each data frame and check for that
// on the client side
// FIXME : the spec says: section 2.6.8 WINDOW_UPDATE:
// "The sender must not send a data frame with data
// length greater than the transfer window size. After
// sending each data frame, the sender decrements its
// transfer window size by the amount of data
// transmitted. When the window size becomes less than
// or equal to 0, the sender must pause transmitting
// data frames."
stream.data(
new StringDataInfo(BugTestClient.MSG, false))
.get();
// we are even waiting that each message was sent
} catch (Exception e) {
System.err.println("Problem while sending data "
+ e.toString());
e.printStackTrace();
}
}
}
};
Thread t = new Thread(task);
t.setDaemon(true);
t.start();
return new StreamFrameListener.Adapter() {
public void onData(final Stream stream, final DataInfo dataInfo) {
// nothing to do
}
};
}
};
// wire up and start the connector
Server server = new Server();
SPDYServerConnector connector = new SPDYServerConnector(frameListener);
connector.setPort(8181);
server.addConnector(connector);
try {
server.start();
server.join();
} catch (Exception e) {
System.err.println("Couldn't start the Jetty server. " + e.toString());
e.printStackTrace();
}
}
}