public void setExtOutputStream(Stream outs) { if(outs!=null) { this.outs_ext=new JStream(outs); } else { this.outs_ext=null; } }
public void close() { try { if(ins!=null)ins.close(); if(outs!=null)outs.close(); if(socket!=null)socket.Close(); } catch(Exception) { } ins=null; outs=null; socket=null; }
public void setInputStream(Stream ins) { //ConsoleStream low buffer patch if(ins!=null) { if(ins.GetType() == Type.GetType("System.IO.__ConsoleStream")) { ins = new Tamir.Streams.ProtectedConsoleStream(ins); } else if(ins.GetType() == Type.GetType("System.IO.FileStream")) { ins = new Tamir.Streams.ProtectedConsoleStream(ins); } this.ins=new JStream(ins); } else { this.ins=null; } }
public void close() { try { if(ins!=null && !in_dontclose) ins.Close(); ins=null; } catch(Exception){} try { if(outs!=null && !out_dontclose) outs.Close(); outs=null; } catch(Exception){} try { if(outs_ext!=null && !outs_ext_dontclose) outs_ext.Close(); outs_ext=null; } catch(Exception){} }
public void connect(SocketFactory socket_factory, String host, int port, int timeout) { try { if(socket_factory==null) { socket=Util.createSocket(proxy_host, proxy_port, timeout); ins= new JStream(new NetworkStream(socket)); outs=new JStream(new NetworkStream(socket)); } else { socket=socket_factory.createSocket(proxy_host, proxy_port); ins=new JStream(socket_factory.getInputStream(socket)); outs=new JStream(socket_factory.getOutputStream(socket)); } if(timeout>0) { socket.ReceiveTimeout = timeout; socket.SendTimeout = timeout; } socket.NoDelay = true; outs.write("CONNECT "+host+":"+port+" HTTP/1.0\r\n"); if(user!=null && passwd!=null) { byte[] _code=Encoding.UTF8.GetBytes(user + ":" + passwd); _code=Util.toBase64(_code, 0, _code.Length); outs.write("Proxy-Authorization: Basic "); outs.write(_code); outs.write("\r\n"); } outs.write("\r\n"); outs.flush(); int foo=0; string sb = ""; while(foo>=0) { foo=ins.read(); if(foo!=13){sb += ((char)foo); continue;} foo=ins.read(); if(foo!=10){continue;} break; } if(foo<0) { throw new System.IO.IOException(); } String response = sb; String reason="Unknow reason"; int code=-1; try { foo=response.IndexOf(' '); int bar=response.IndexOf(' ', foo+1); code = System.Convert.ToInt32(response.Substring(foo + 1, bar)); reason=response.Substring(bar+1); } catch(Exception) { } if(code!=200) { throw new System.IO.IOException("proxy error: "+reason); } /* while(foo>=0){ foo=in.read(); if(foo!=13) continue; foo=in.read(); if(foo!=10) continue; foo=in.read(); if(foo!=13) continue; foo=in.read(); if(foo!=10) continue; break; } */ int count=0; while(true) { count=0; while(foo>=0) { foo=ins.read(); if(foo!=13){count++; continue;} foo=ins.read(); if(foo!=10){continue;} break; } if(foo<0) { throw new System.IO.IOException(); } if(count==0)break; } } catch(Exception e) { try{ if(socket!=null)socket.Close(); } catch(Exception) { } String message="ProxyHTTP: "+e.ToString(); throw e; } }