当前位置: 首页>>代码示例>>C#>>正文


C# Socket.GetOutputStream方法代码示例

本文整理汇总了C#中Socket.GetOutputStream方法的典型用法代码示例。如果您正苦于以下问题:C# Socket.GetOutputStream方法的具体用法?C# Socket.GetOutputStream怎么用?C# Socket.GetOutputStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Socket的用法示例。


在下文中一共展示了Socket.GetOutputStream方法的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());
			}
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:98,代码来源:ProxySOCKS4.cs

示例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);
		}
开发者ID:nickname100,项目名称:monodevelop,代码行数:27,代码来源:DaemonClient.cs


注:本文中的Socket.GetOutputStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。