Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 351389

Summary: General purpose WebSocket client
Product: [RT] Jetty Reporter: Missing name <andrej.golovnin>
Component: clientAssignee: Jan Bartel <janb>
Status: CLOSED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: gregw, janbo999, jetty-inbox
Version: unspecified   
Target Milestone: 7.4.x   
Hardware: PC   
OS: All   
Whiteboard:

Description Missing name CLA 2011-07-07 03:15:39 EDT
Build Identifier: 

Please add a general purpose WebSocket client implementation to Jetty.
My small list of requirements for WebSocket client implementation in Jetty:
- the client WebSocket should support both ws and wss protocols.
- it should be possible to send and receive arbitrary long binary messages.
- when sending binary messages it should be possible to specify a byte array, the offset and the length (similar to what I can do today on the server: Connection#sendMessage(byte[], int, int))

Thanks in advance!

Reproducible: Always
Comment 1 janbo999 CLA 2011-07-20 10:18:16 EDT
one working example:

public class MySockWEB implements WebSocket, WebSocket.OnBinaryMessage, WebSocket.OnTextMessage{

..........................

	public MySockWEB(String addr, int port) throws IOException {
		Socket socket = new Socket(addr, port);
		socket.setSoTimeout(6000);
		BufferedWriter output = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "ISO-8859-1"));
		BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream(), "ISO-8859-1"));
		output.write("GET /test HTTP/1.1\r\nHost: localhost\r\nUpgrade: WebSocket\r\nConnection: Upgrade\r\n\r\n");
		output.flush();
		String responseLine = input.readLine();
//		System.out.println(responseLine);
		if(!responseLine.startsWith("HTTP/1.1 101 Web Socket Protocol Handshake")){
			throw new IOException("bad server response");
		}
		String line;
		while ((line = input.readLine()) != null){
//			System.out.println(line);
			if (line.length() == 0){
				break;
			}
		}
		ep = new SocketEndPoint(socket);
		co = new WebSocketConnectionD00(this, ep, new WebSocketBuffers(32768), (long)0, 60000, "");
		this.onOpen(((WebSocketConnectionD00)co));
		new Thread(){
			public void run(){
				while (ep.isOpen()){
					try {
						co.handle();
					} catch (IOException e) {
						e.printStackTrace();
					}
                                    Thread.sleep(1);
				}
		     }
		}.start();
	}
Comment 2 Greg Wilkins CLA 2011-08-29 00:23:47 EDT
A websocket client has been added to jetty for the 7.5.0 release.

http://webtide.intalio.com/2011/08/websocket-example-server-client-and-loadtest/
Comment 3 Jesse McConnell CLA 2011-09-20 15:52:24 EDT
Resolved -> Closed