package javaforce.service;
import java.io.*;
import java.net.*;
import javaforce.*;
/** WebSocket
*
* @author pquiring
*
* See : RFC 6455
*/
public class WebSocket {
protected InputStream is;
protected OutputStream os;
protected String host;
protected String url;
protected String[] cookies;
private boolean connected = true;
private String server_host;
private String client_host;
public static final int TYPE_CONT = 0x0; //do not use
public static final int TYPE_TEXT = 0x1;
public static final int TYPE_BINARY = 0x2;
protected static final int TYPE_CLOSE = 0x08;
protected static final int TYPE_PING = 0x09;
protected static final int TYPE_PONG = 0x0a;
public static final int FIN = 0x80;
public static final int MASK = 0x80;
public WebSocket(String server_host, String client_host, InputStream is, OutputStream os, String host, String url, String[] cookies) {
if (server_host.equals("0:0:0:0:0:0:0:1")) {
server_host = "127.0.0.1";
}
this.server_host = server_host;
if (client_host.equals("0:0:0:0:0:0:0:1")) {
client_host = "127.0.0.1";
}
this.client_host = client_host;
this.is = is;
this.os = os;
this.host = host;
this.url = url;
this.cookies = cookies;
}
/** Free to use data */
public Object userobj;
/** Returns URL used during WebSocket connection request. */
public String getURL() {
return url;
}
public String getClientHost() {
return client_host;
}
public String getServerHost() {
return server_host;
}
public String getHost() {
return host;
}
public InputStream getInputStream() {
return is;
}
public OutputStream getOutputStream() {
return os;
}
public String[] getCookies() {
return cookies;
}
public String getCookie(String name) {
name += "=";
for(int a=0;a