Advertisement
Guest User

Test Server

a guest
May 29th, 2012
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.89 KB | None | 0 0
  1. import org.eclipse.jetty.server.Server;
  2. import org.eclipse.jetty.spdy.IStream;
  3. import org.eclipse.jetty.spdy.SPDYServerConnector;
  4. import org.eclipse.jetty.spdy.api.DataInfo;
  5. import org.eclipse.jetty.spdy.api.ReplyInfo;
  6. import org.eclipse.jetty.spdy.api.Stream;
  7. import org.eclipse.jetty.spdy.api.StreamFrameListener;
  8. import org.eclipse.jetty.spdy.api.StringDataInfo;
  9. import org.eclipse.jetty.spdy.api.SynInfo;
  10. import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener;
  11.  
  12. /**
  13.  * Server.<br/>
  14.  * Note: Put
  15.  * <code>-Xbootclasspath/p:lib/spdy/npn-boot-7.6.2.v20120308.jar</code> as
  16.  * vmarg.
  17.  */
  18. public class BugTestServer {
  19.  
  20.    public static void main(final String[] args) throws Exception {
  21.       // Frame listener that handles the communication over speedy
  22.       ServerSessionFrameListener frameListener = new ServerSessionFrameListener.Adapter() {
  23.  
  24.          @Override
  25.          public StreamFrameListener onSyn(final Stream stream,
  26.                final SynInfo synInfo) {
  27.             // Send a reply to this message
  28.             try {
  29.                stream.reply(new ReplyInfo(false)).get();
  30.             } catch (Exception e) {
  31.                System.err.println(e.toString());
  32.             }
  33.  
  34.             // start new message sender thread
  35.             Runnable task = new Runnable() {
  36.  
  37.                public void run() {
  38.                   while (true) {
  39.                      try {
  40.                         IStream s = (IStream) stream;
  41.                         System.out.println(s.getWindowSize());
  42.  
  43.                         // FIXME : Here is the problem, the client updates the
  44.                         // window size down from 64K to 300 then 100 then 56 and
  45.                         // even 0 bytes, the server then truncates data frames,
  46.                         // check whether this is legal according to the spec
  47.  
  48.                         // TODO : a workaround for us is to have a terminator
  49.                         // (e.g. checksum) in each data frame and check for that
  50.                         // on the client side
  51.  
  52.                         // FIXME : the spec says: section 2.6.8 WINDOW_UPDATE:
  53.                         // "The sender must not send a data frame with data
  54.                         // length greater than the transfer window size. After
  55.                         // sending each data frame, the sender decrements its
  56.                         // transfer window size by the amount of data
  57.                         // transmitted. When the window size becomes less than
  58.                         // or equal to 0, the sender must pause transmitting
  59.                         // data frames."
  60.  
  61.                         stream.data(
  62.                               new StringDataInfo(BugTestClient.MSG, false))
  63.                               .get();
  64.                         // we are even waiting that each message was sent
  65.                      } catch (Exception e) {
  66.                         System.err.println("Problem while sending data "
  67.                               + e.toString());
  68.                         e.printStackTrace();
  69.                      }
  70.                   }
  71.                }
  72.             };
  73.             Thread t = new Thread(task);
  74.             t.setDaemon(true);
  75.             t.start();
  76.  
  77.             return new StreamFrameListener.Adapter() {
  78.                public void onData(final Stream stream, final DataInfo dataInfo) {
  79.                   // nothing to do
  80.                }
  81.             };
  82.          }
  83.       };
  84.  
  85.       // wire up and start the connector
  86.       Server server = new Server();
  87.       SPDYServerConnector connector = new SPDYServerConnector(frameListener);
  88.       connector.setPort(8181);
  89.       server.addConnector(connector);
  90.  
  91.       try {
  92.          server.start();
  93.          server.join();
  94.       } catch (Exception e) {
  95.          System.err.println("Couldn't start the Jetty server. " + e.toString());
  96.          e.printStackTrace();
  97.       }
  98.    }
  99.  
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement