public void put(Packet p) { outs.Write(p.buffer.buffer, 0, p.buffer.index); outs.Flush(); }
internal void put_ext(byte[] array, int begin, int length) { outs_ext.Write(array, begin, length); outs_ext.Flush(); }
public void Connect(SocketFactory socketFactory, String host, int port, int timeout) { try { if (socketFactory == null) { Socket = Util.createSocket(Host, Port, timeout); inputStream = new JStream(Socket.getInputStream()); outputStream = new JStream(Socket.getOutputStream()); } else { Socket = socketFactory.createSocket(Host, Port); inputStream = new JStream(socketFactory.getInputStream(Socket)); outputStream = new JStream(socketFactory.getOutputStream(Socket)); } if (timeout > 0) { Socket.setSoTimeout(timeout); } Socket.setTcpNoDelay(true); outputStream.Write(("CONNECT " + host + ":" + port + " HTTP/1.0\r\n").GetBytes()); if (User != null && Password != null) { byte[] _code = (User + ":" + Password).GetBytes(); _code = Util.toBase64(_code, 0, _code.Length); outputStream.Write("Proxy-Authorization: Basic ".GetBytes()); outputStream.Write(_code); outputStream.Write("\r\n".GetBytes()); } outputStream.Write("\r\n".GetBytes()); outputStream.flush(); int foo = 0; StringBuilder sb = new StringBuilder(); while (foo >= 0) { foo = inputStream.read(); if (foo != 13) { sb.Append((char)foo); continue; } foo = inputStream.read(); if (foo != 10) { continue; } break; } if (foo < 0) { throw new IOException(); } String response = sb.ToString(); String reason = "Unknow reason"; int code = -1; try { foo = response.IndexOf(' '); int bar = response.IndexOf(' ', foo + 1); code = Int32.Parse(response.Substring(foo + 1, bar)); reason = response.Substring(bar + 1); } catch (Exception) { } if (code != 200) { throw new IOException("proxy error: " + reason); } int count = 0; while (true) { count = 0; while (foo >= 0) { foo = inputStream.read(); if (foo != 13) { count++; continue; } foo = inputStream.read(); if (foo != 10) { continue; } break; } if (foo < 0) { throw new IOException(); } if (count == 0) { break; } } } catch (Exception e) { try { if (Socket != null) { Socket.Close(); } } catch (Exception) { } String message = "ProxyHTTP: " + e; throw e; } }