本文整理汇总了C#中Socket.GetInputStream方法的典型用法代码示例。如果您正苦于以下问题:C# Socket.GetInputStream方法的具体用法?C# Socket.GetInputStream怎么用?C# Socket.GetInputStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Socket
的用法示例。
在下文中一共展示了Socket.GetInputStream方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
index = 0;
buf[index++] = 4;
buf[index++] = 1;
buf[index++] = unchecked((byte)((int)(((uint)port) >> 8)));
buf[index++] = unchecked((byte)(port & unchecked((int)(0xff))));
try
{
IPAddress addr = Sharpen.Extensions.GetAddressByName(host);
byte[] byteAddress = addr.GetAddressBytes();
for (int i = 0; i < byteAddress.Length; i++)
{
buf[index++] = byteAddress[i];
}
}
catch (UnknownHostException uhe)
{
throw new JSchException("ProxySOCKS4: " + uhe.ToString(), uhe);
}
if (user != null)
{
System.Array.Copy(Util.Str2byte(user), 0, buf, index, user.Length);
index += user.Length;
}
buf[index++] = 0;
@out.Write(buf, 0, index);
int len = 8;
int s = 0;
while (s < len)
{
int i = @in.Read(buf, s, len - s);
if (i <= 0)
{
throw new JSchException("ProxySOCKS4: stream is closed");
}
s += i;
}
if (buf[0] != 0)
{
throw new JSchException("ProxySOCKS4: server returns VN " + buf[0]);
}
if (buf[1] != 90)
{
try
{
socket.Close();
}
catch (Exception)
{
}
string message = "ProxySOCKS4: server returns CD " + buf[1];
throw new JSchException(message);
}
}
catch (RuntimeException e)
{
throw;
}
catch (Exception e)
{
try
{
if (socket != null)
{
socket.Close();
}
}
catch (Exception)
{
}
throw new JSchException("ProxySOCKS4: " + e.ToString());
}
}
示例2: Execute
/// <exception cref="System.IO.IOException"></exception>
internal virtual void Execute(Socket sock)
{
rawIn = new BufferedInputStream(sock.GetInputStream());
rawOut = new BufferedOutputStream(sock.GetOutputStream());
if (0 < daemon.GetTimeout())
{
sock.ReceiveTimeout = daemon.GetTimeout() * 1000;
}
string cmd = new PacketLineIn(rawIn).ReadStringRaw();
int nul = cmd.IndexOf('\0');
if (nul >= 0)
{
// Newer clients hide a "host" header behind this byte.
// Currently we don't use it for anything, so we ignore
// this portion of the command.
//
cmd = Sharpen.Runtime.Substring(cmd, 0, nul);
}
DaemonService srv = GetDaemon().MatchService(cmd);
if (srv == null)
{
return;
}
sock.ReceiveTimeout = 0;
srv.Execute(this, cmd);
}