本文整理汇总了C#中System.Proxy.close方法的典型用法代码示例。如果您正苦于以下问题:C# Proxy.close方法的具体用法?C# Proxy.close怎么用?C# Proxy.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Proxy
的用法示例。
在下文中一共展示了Proxy.close方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: connect
public void connect(int connectTimeout)
{
if(_isConnected)
{
throw new JSchException("session is already connected");
}
io=new IO();
if(random==null)
{
try
{
random = (Random)System.Activator.CreateInstance(System.Type.GetType(getConfig("random")));
}
catch(Exception e)
{
System.Console.Error.WriteLine("connect: random "+e);
}
}
Packet.setRandom(random);
try
{
int i, j;
//int pad=0;
if(proxy==null)
{
proxy=jsch.getProxy(host);
if(proxy!=null)
{
lock(proxy)
{
proxy.close();
}
}
}
if(proxy==null)
{
Stream In;
Stream Out;
if(socket_factory==null)
{
socket=Util.createSocket(host, port, connectTimeout);
In=new NetworkStream(socket);
Out=new NetworkStream(socket);
}
else
{
socket=socket_factory.createSocket(host, port);
In=socket_factory.getInputStream(socket);
Out=socket_factory.getOutputStream(socket);
}
//if(timeout>0){ socket.setSoTimeout(timeout); }
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, true);
io.setInputStream(In);
io.setOutputStream(Out);
}
else
{
lock (proxy)
{
proxy.connect(socket_factory, host, port, connectTimeout);
io.setInputStream(proxy.getInputStream());
io.setOutputStream(proxy.getOutputStream());
socket=proxy.getSocket();
}
}
if (connectTimeout > 0 && socket != null)
{
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, connectTimeout);
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, connectTimeout);
}
_isConnected=true;
while(true)
{
i=0;
j=0;
while(i<buf.buffer.Length)
{
j=io.getByte();
if(j<0)break;
buf.buffer[i]=(byte)j; i++;
if(j==10)break;
}
if(j<0)
{
throw new JSchException("connection is closed by foreign host");
}
if(buf.buffer[i-1]==10)
{ // 0x0a
i--;
if(buf.buffer[i-1]==13)
{ // 0x0d
i--;
//.........这里部分代码省略.........
示例2: connect
public void connect(int connectTimeout)
{
if(random==null)
{
try
{
Type t=Type.GetType(getConfig("random"));
random=(Random)(Activator.CreateInstance(t));
}
catch(Exception e){ Console.Error.WriteLine("connect: random "+e); }
}
Packet.setRandom(random);
try
{
int i, j;
//int pad=0;
if(proxy==null)
{
proxy=jsch.getProxy(host);
if(proxy!=null)
{
lock(proxy)
{
proxy.close();
}
}
}
IPEndPoint ipe=null;
if(proxy==null)
{
Stream ins;
Stream outs;
if(socket_factory==null)
{
if(connectTimeout==0)
{
ipe = new IPEndPoint(Dns.GetHostByName(host).AddressList[0], port);
socket=new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
}
// String message="";
// Thread tmp=new Thread(new Runnable(){
// public void run(){
// try{
// sockp[0]=new Socket(host, port);
// if(done[0]){
// if(sockp[0]!=null){
// sockp[0].close();
// sockp[0]=null;
// }
// }
// else thread.interrupt();
// }
// catch(Exception e){
// ee[0]=e;
// thread.interrupt();
// if(sockp[0]!=null){
// try{
// sockp[0].close();
// sockp[0]=null;
// }catch(Exception eee){}
// }
// }
// }
// });
// tmp.start();
// try{
// Thread.sleep(connectTimeout);
// message="timeout: ";
// }
// catch(java.lang.InterruptedException eee){
// tmp.interrupt();
// tmp=null;
// System.gc();
// }
// done[0]=true;
// if(sockp[0]!=null){
// socket=sockp[0];
// }
// else{
// message+="socket is not established";
// if(ee[0]!=null){
// message=ee[0].toString();
// }
// throw new JSchException(message);
// }
// }
socket.Connect(ipe);
NetworkStream ns = new NetworkStream( socket );
ins=ns;
outs=ns;
}
else
{
socket=socket_factory.createSocket(host, port);
ins=socket_factory.getInputStream(socket);
outs=socket_factory.getOutputStream(socket);
}
if(timeout>0)
//.........这里部分代码省略.........