* Implements the connection establishment protocol.
*/
public HttpTunnelConnection doConnect() throws IOException {
URL connUrl = new URL(urlString + "?Type=connect" + urlParam);
HttpTunnelPacket p = new HttpTunnelPacket();
p.setPacketType(CONN_INIT_PACKET);
p.setPacketBody(null);
p.setConnId(0);
p.setSequence(0);
p.setWinsize(0);
p.setChecksum(0);
try {
HttpTunnelPacket resp = pushWorker.sendPacketDirect(connUrl, p, true);
connId = resp.getConnId();
String serverName = new String(resp.getPacketBody(), "UTF8");
String newurlParam = "&" + serverName;
if (!urlParam.equals("") && !newurlParam.equals(urlParam)) {
throw new IOException("Unexpected new ServerName: " +
serverName);
}
if (urlParam.equals("")) {
urlParam = newurlParam;
}
pushUrl = new URL(urlString + "?Type=push" + urlParam);
pullUrl = new URL(urlString + "?Type=pull&ConnId=" + connId +
urlParam);
while (conn == null) {
Vector v = pullPackets();
if ((v == null) || (v.size() == 0)) {
continue;
}
HttpTunnelPacket ack = (HttpTunnelPacket) v.elementAt(0);
if (ack != null) {
switch (ack.getPacketType()) {
case CONN_SHUTDOWN:
throw new IOException("Connection refused");
case CONN_INIT_ACK:
handleConnInitAck(ack);