Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.net.InetSocketAddress;
- import java.util.concurrent.Future;
- import java.util.concurrent.TimeUnit;
- import org.eclipse.jetty.spdy.SPDYClient;
- import org.eclipse.jetty.spdy.api.DataInfo;
- import org.eclipse.jetty.spdy.api.SPDY;
- import org.eclipse.jetty.spdy.api.Session;
- import org.eclipse.jetty.spdy.api.Stream;
- import org.eclipse.jetty.spdy.api.StreamFrameListener;
- import org.eclipse.jetty.spdy.api.SynInfo;
- /**
- * Client. <br/>
- * Put <code>-Xbootclasspath/p:lib/spdy/npn-boot-7.6.2.v20120308.jar</code> as
- * vmarg.
- */
- public class BugTestClient {
- /**
- * The message that the server is expected to send
- */
- public static final String MSG = "This is the message that the server is supposed to send.";
- private static final String SERVER_ADDRESS = "localhost";
- private static final int SERVER_PORT = 8181;
- public static void main(final String[] args) throws Exception {
- // create client
- SPDYClient.Factory clientFactory = new SPDYClient.Factory();
- try {
- clientFactory.start();
- } catch (Exception e) {
- System.err.println("Couldn't start client factory. " + e.toString());
- System.exit(1);
- }
- SPDYClient client = clientFactory.newSPDYClient(SPDY.V3);
- // create a session to the server
- Session session = null;
- try {
- Future<Session> future = client.connect(new InetSocketAddress(
- SERVER_ADDRESS, SERVER_PORT), null);
- session = future.get();
- } catch (Exception e) {
- System.err.println("Couldn't connect to server at " + SERVER_ADDRESS
- + ":" + SERVER_PORT + ". Aborting.");
- System.exit(1);
- }
- // this listener receives data from the server and prints it
- StreamFrameListener streamListener = new StreamFrameListener.Adapter() {
- private long numArrived = 0;
- public void onData(final Stream stream, final DataInfo dataInfo) {
- // Data received from server
- String content = dataInfo.asString("UTF-8", true);
- if (!content.equals(MSG)) {
- // bug?
- System.err
- .println("The server did not send the correct message: '"
- + content + "'");
- }
- numArrived++;
- if (numArrived % 20000 == 0) {
- System.out.println(numArrived + " messages arrrived");
- }
- }
- };
- // Start a new session, and configure the stream listener
- try {
- session.syn(new SynInfo(false), streamListener).get(5,
- TimeUnit.SECONDS);
- System.out.println("Stream opened.");
- } catch (Exception e) {
- System.err.println("Problem with stream. " + e.toString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement