本文整理汇总了C#中System.Net.Sockets.Socket.GetOutputStream方法的典型用法代码示例。如果您正苦于以下问题:C# Socket.GetOutputStream方法的具体用法?C# Socket.GetOutputStream怎么用?C# Socket.GetOutputStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Sockets.Socket
的用法示例。
在下文中一共展示了Socket.GetOutputStream方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Connect
/// <exception cref="NSch.JSchException"></exception>
public virtual void Connect(int connectTimeout)
{
if (isConnected)
{
throw new JSchException("session is already connected");
}
io = new IO();
if (random == null)
{
try
{
Type c = Sharpen.Runtime.GetType(GetConfig("random"));
random = (Random)(System.Activator.CreateInstance(c));
}
catch (Exception e)
{
throw new JSchException(e.ToString(), e);
}
}
Packet.SetRandom(random);
if (JSch.GetLogger().IsEnabled(Logger.INFO))
{
JSch.GetLogger().Log(Logger.INFO, "Connecting to " + host + " port " + port);
}
try
{
int i;
int j;
if (proxy == null)
{
InputStream @in;
OutputStream @out;
if (socket_factory == null)
{
socket = Util.CreateSocket(host, port, connectTimeout);
@in = socket.GetInputStream();
@out = socket.GetOutputStream();
}
else
{
socket = socket_factory.CreateSocket(host, port);
@in = socket_factory.GetInputStream(socket);
@out = socket_factory.GetOutputStream(socket);
}
//if(timeout>0){ socket.setSoTimeout(timeout); }
socket.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.ReceiveTimeout = connectTimeout;
}
isConnected = true;
if (JSch.GetLogger().IsEnabled(Logger.INFO))
{
JSch.GetLogger().Log(Logger.INFO, "Connection established");
}
jsch.AddSession(this);
{
// Some Cisco devices will miss to read '\n' if it is sent separately.
byte[] foo = new byte[V_C.Length + 1];
System.Array.Copy(V_C, 0, foo, 0, V_C.Length);
foo[foo.Length - 1] = unchecked((byte)(byte)('\n'));
io.Put(foo, 0, foo.Length);
}
while (true)
{
i = 0;
j = 0;
while (i < buf.buffer.Length)
{
j = io.GetByte();
if (j < 0)
{
break;
}
buf.buffer[i] = unchecked((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)
//.........这里部分代码省略.........
示例2: Connect
/// <exception cref="NSch.JSchException"></exception>
public virtual void Connect(SocketFactory socket_factory, string host, int port,
int timeout)
{
try
{
if (socket_factory == null)
{
socket = Util.CreateSocket(proxy_host, proxy_port, timeout);
@in = socket.GetInputStream();
@out = socket.GetOutputStream();
}
else
{
socket = socket_factory.CreateSocket(proxy_host, proxy_port);
@in = socket_factory.GetInputStream(socket);
@out = socket_factory.GetOutputStream(socket);
}
if (timeout > 0)
{
socket.ReceiveTimeout = timeout;
}
socket.NoDelay = true;
@out.Write(Util.Str2byte("CONNECT " + host + ":" + port + " HTTP/1.0\r\n"));
if (user != null && passwd != null)
{
byte[] code = Util.Str2byte(user + ":" + passwd);
code = Util.ToBase64(code, 0, code.Length);
@out.Write(Util.Str2byte("Proxy-Authorization: Basic "));
@out.Write(code);
@out.Write(Util.Str2byte("\r\n"));
}
@out.Write(Util.Str2byte("\r\n"));
@out.Flush();
int foo = 0;
StringBuilder sb = new StringBuilder();
while (foo >= 0)
{
foo = @in.Read();
if (foo != 13)
{
sb.Append((char)foo);
continue;
}
foo = @in.Read();
if (foo != 10)
{
continue;
}
break;
}
if (foo < 0)
{
throw new IOException();
}
string response = sb.ToString();
string reason = "Unknow reason";
int code_1 = -1;
try
{
foo = response.IndexOf(' ');
int bar = response.IndexOf(' ', foo + 1);
code_1 = System.Convert.ToInt32(Sharpen.Runtime.Substring(response, foo + 1, bar)
);
reason = Sharpen.Runtime.Substring(response, bar + 1);
}
catch (Exception)
{
}
if (code_1 != 200)
{
throw new IOException("proxy error: " + reason);
}
int count = 0;
while (true)
{
count = 0;
while (foo >= 0)
{
foo = @in.Read();
if (foo != 13)
{
count++;
continue;
}
foo = @in.Read();
if (foo != 10)
{
continue;
}
break;
}
if (foo < 0)
{
throw new IOException();
}
if (count == 0)
{
break;
}
//.........这里部分代码省略.........
示例3: Run
public override void Run()
{
try
{
socket = Util.CreateSocket(host, port, TIMEOUT);
socket.NoDelay = true;
io = new IO();
io.SetInputStream(socket.GetInputStream());
io.SetOutputStream(socket.GetOutputStream());
SendOpenConfirmation();
}
catch (Exception)
{
SendOpenFailure(SSH_OPEN_ADMINISTRATIVELY_PROHIBITED);
close = true;
Disconnect();
return;
}
thread = Sharpen.Thread.CurrentThread();
Buffer buf = new Buffer(rmpsize);
Packet packet = new Packet(buf);
int i = 0;
try
{
while (thread != null && io != null && [email protected] != null)
{
i = [email protected](buf.buffer, 14, buf.buffer.Length - 14 - 32 - 20);
// padding and mac
if (i <= 0)
{
Eof();
break;
}
if (close)
{
break;
}
packet.Reset();
buf.PutByte(unchecked((byte)Session.SSH_MSG_CHANNEL_DATA));
buf.PutInt(recipient);
buf.PutInt(i);
buf.Skip(i);
GetSession().Write(packet, this, i);
}
}
catch (Exception)
{
}
//System.err.println(e);
Disconnect();
}
示例4: Run
public override void Run()
{
try
{
if (lport == -1)
{
Type c = Sharpen.Runtime.GetType(target);
daemon = (ForwardedTCPIPDaemon)System.Activator.CreateInstance(c);
PipedOutputStream @out = new PipedOutputStream();
io.SetInputStream(new Channel.PassiveInputStream(this, @out, 32 * 1024), false);
daemon.SetChannel(this, GetInputStream(), @out);
object[] foo = GetPort(GetSession(), rport);
daemon.SetArg((object[])foo[3]);
new Sharpen.Thread(daemon).Start();
}
else
{
socket = (factory == null) ? Util.CreateSocket(target, lport, TIMEOUT) : factory.
CreateSocket(target, lport);
socket.NoDelay = true;
io.SetInputStream(socket.GetInputStream());
io.SetOutputStream(socket.GetOutputStream());
}
SendOpenConfirmation();
}
catch (Exception)
{
SendOpenFailure(SSH_OPEN_ADMINISTRATIVELY_PROHIBITED);
close = true;
Disconnect();
return;
}
thread = Sharpen.Thread.CurrentThread();
Buffer buf = new Buffer(rmpsize);
Packet packet = new Packet(buf);
int i = 0;
try
{
while (thread != null && io != null && [email protected] != null)
{
i = [email protected](buf.buffer, 14, buf.buffer.Length - 14 - 32 - 20);
// padding and mac
if (i <= 0)
{
Eof();
break;
}
packet.Reset();
if (close)
{
break;
}
buf.PutByte(unchecked((byte)Session.SSH_MSG_CHANNEL_DATA));
buf.PutInt(recipient);
buf.PutInt(i);
buf.Skip(i);
GetSession().Write(packet, this, i);
}
}
catch (Exception)
{
}
//System.err.println(e);
//thread=null;
//eof();
Disconnect();
}
示例5: Connect
/// <exception cref="NSch.JSchException"></exception>
public virtual void Connect(SocketFactory socket_factory, string host, int port,
int timeout)
{
try
{
if (socket_factory == null)
{
socket = Util.CreateSocket(proxy_host, proxy_port, timeout);
//socket=new Socket(proxy_host, proxy_port);
@in = socket.GetInputStream();
@out = socket.GetOutputStream();
}
else
{
socket = socket_factory.CreateSocket(proxy_host, proxy_port);
@in = socket_factory.GetInputStream(socket);
@out = socket_factory.GetOutputStream(socket);
}
if (timeout > 0)
{
socket.ReceiveTimeout = timeout;
}
socket.NoDelay = true;
byte[] buf = new byte[1024];
int index = 0;
buf[index++] = 5;
buf[index++] = 2;
buf[index++] = 0;
// NO AUTHENTICATION REQUIRED
buf[index++] = 2;
// USERNAME/PASSWORD
@out.Write(buf, 0, index);
//in.read(buf, 0, 2);
Fill(@in, buf, 2);
bool check = false;
switch ((buf[1]) & unchecked((int)(0xff)))
{
case 0:
{
// NO AUTHENTICATION REQUIRED
check = true;
break;
}
case 2:
{
// USERNAME/PASSWORD
if (user == null || passwd == null)
{
break;
}
index = 0;
buf[index++] = 1;
buf[index++] = unchecked((byte)(user.Length));
System.Array.Copy(Util.Str2byte(user), 0, buf, index, user.Length);
index += user.Length;
buf[index++] = unchecked((byte)(passwd.Length));
System.Array.Copy(Util.Str2byte(passwd), 0, buf, index, passwd.Length);
index += passwd.Length;
@out.Write(buf, 0, index);
//in.read(buf, 0, 2);
Fill(@in, buf, 2);
if (buf[1] == 0)
{
check = true;
}
break;
}
default:
{
break;
}
}
if (!check)
{
try
{
socket.Close();
}
catch (Exception)
{
}
throw new JSchException("fail in SOCKS5 proxy");
}
index = 0;
buf[index++] = 5;
buf[index++] = 1;
// CONNECT
buf[index++] = 0;
byte[] hostb = Util.Str2byte(host);
int len = hostb.Length;
buf[index++] = 3;
// DOMAINNAME
buf[index++] = unchecked((byte)(len));
System.Array.Copy(hostb, 0, buf, index, len);
index += len;
buf[index++] = unchecked((byte)((int)(((uint)port) >> 8)));
buf[index++] = unchecked((byte)(port & unchecked((int)(0xff))));
//.........这里部分代码省略.........