| Summary: | General purpose WebSocket client | ||
|---|---|---|---|
| Product: | [RT] Jetty | Reporter: | Missing name <andrej.golovnin> |
| Component: | client | Assignee: | 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
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();
}
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/ Resolved -> Closed |