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


C# TcpClient.GetStream方法代码示例

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


在下文中一共展示了TcpClient.GetStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Player

        public Player(TcpClient client, string ip, byte id)
        {
            try
            {
                this.username = "player";
                this.plyClient = client;
                this.x = 0;
                this.y = 0;
                this.z = 0;
                this.rotx = 0;
                this.roty = 0;
                this.prefix = "";
                this.id = id;
                this.ip = ip;

                this.world = null;

                this.outQueue = new Queue<Packet>();
                this.blockQueue = new Queue<Packet>();
                this.IOThread = new Thread(PlayerIO);
                this.outputWriter = new BinaryWriter(client.GetStream());
                this.inputReader = new BinaryReader(client.GetStream());

                this.IOThread.IsBackground = true;
                this.IOThread.Start();
            }
            catch
            {
            }
        }
开发者ID:roy12345,项目名称:uMiner,代码行数:30,代码来源:Player.cs

示例2: StreamingAPIConnect

        public StreamingAPIConnect(StreamingListener sl, string ip, int port, LoginResponse lr, bool secure)
        {
            this.sl = sl;
            this.streamingSessionId = lr.StreamingSessionId;
            apiSocket = new System.Net.Sockets.TcpClient(ip, port);
            if (secure)
            {
                SslStream ssl = new SslStream(apiSocket.GetStream());
                ssl.AuthenticateAsClient("xtb.com"); //hardcoded domain, because we use ip-version of the address
                apiWriteStream = new StreamWriter(ssl);
                apiBufferedReader = new StreamReader(ssl);
            }
            else
            {
                NetworkStream ns = apiSocket.GetStream();
                apiWriteStream = new StreamWriter(ns);
                apiBufferedReader = new StreamReader(ns);
            }

            Thread t = new Thread(delegate()
            {
                while (running)
                {
                    readStreamMessage();
                    Thread.Sleep(50);
                }
            });
            t.Start();
            //System.Threading.Timer t = new System.Threading.Timer(o => readStreamMessage(), null, 0, 10);
        }
开发者ID:del19,项目名称:Cwiczebny,代码行数:30,代码来源:StreamingAPIConnect.cs

示例3: TestListen

        public void TestListen()
        {
            try
            {
                Identd.Start("username");
                Thread.Sleep( 1000 );

                TcpClient client = new TcpClient();
                client.Connect("localhost", 113);

                StreamWriter writer = new StreamWriter( client.GetStream() );
                writer.WriteLine( "a query" );
                writer.Flush();

                StreamReader reader = new StreamReader( client.GetStream() );
                string line = reader.ReadLine();

                Identd.Stop();

                Assertion.AssertEquals( "a query : USERID : UNIX : username", line.Trim() );
            }
            catch( Exception e )
            {
                Assertion.Fail("IO Exception during test:" + e);
            }
        }
开发者ID:Iciclebar,项目名称:ThreshIRC,代码行数:26,代码来源:IdentdTest.cs

示例4: OpenConnection

 internal static string OpenConnection()
 {
     errorMsg = string.Empty;
     _dataBuffer = string.Empty;
     int result = 0;
     int.TryParse(ConfigurationSupport.currentPort, out result);
     try
     {
         _client = new TcpClient(ConfigurationSupport.currentHost, result);
         string str = QuickRead(null);
         if (str != ConfigurationSupport.version)
         {
             errorMsg = errorMsg + "Mismatched versions." + Environment.NewLine;
             errorMsg = errorMsg + string.Format("SERVER: ({0})" + Environment.NewLine, str);
             errorMsg = errorMsg + string.Format("CLIENT: ({0})" + Environment.NewLine, ConfigurationSupport.version);
             CloseConnection();
         }
         if (_client.Connected)
         {
             StreamWriter writer = new StreamWriter(_client.GetStream());
             writer.WriteLine(string.Format("VersionInfo {{{0}}}", ConfigurationSupport.version));
             writer.Flush();
             _sslStreamReader = new SslStream(_client.GetStream(), false, new RemoteCertificateValidationCallback(CertificateValidationCallBack));
             try
             {
                 _sslStreamReader.AuthenticateAsClient(ConfigurationSupport.currentHost, null, SslProtocols.Ssl3, false);
             }
             catch (AuthenticationException exception)
             {
                 errorMsg = errorMsg + "SSL Authentication Error." + Environment.NewLine;
                 errorMsg = errorMsg + exception.ToString();
             }
             _sslStreamWriter = new StreamWriter(_sslStreamReader);
             _sslStreamWriter.AutoFlush = true;
             _sslStreamWriter.WriteLine(string.Format("ValidateUser {0} {1}", ConfigurationSupport.currentUsername, ConfigurationSupport.currentPassword));
             string str2 = QuickRead(_sslStreamReader);
             if (str2 == "UserID INVALID")
             {
                 CloseConnection();
                 errorMsg = "Invalid USERNAME and/or PASSWORD";
             }
             else
             {
                 isConnected = true;
                 ConfigurationSupport.userID = str2.Split(new char[0])[1];
             }
         }
     }
     catch (Exception ex)
     {
         isConnected = false;
         errorMsg = string.Format("Could not connect to {0}:{1}", ConfigurationSupport.currentHost, ConfigurationSupport.currentPort);
     }
     if (isConnected)
     {
         _readBuffer = new byte[0x100];
         _sslStreamReader.BeginRead(_readBuffer, 0, _readBuffer.Length, new AsyncCallback(SguildConnection.OnReceivedData), _client.GetStream());
     }
     return errorMsg;
 }
开发者ID:PingTrip,项目名称:PT-Sguil,代码行数:60,代码来源:SguildConnection.cs

示例5: ListFiles

        public static string ListFiles()
        {
            using (TcpClient socket = new TcpClient())
            {
                string total = null;
                socket.Connect(IPAddress.Loopback, PORT);

                StreamWriter output = new StreamWriter(socket.GetStream());

                // Send request type line
                output.WriteLine("LIST_FILES");
                // Send message end mark and flush it
                output.WriteLine();
                output.Flush();

                // Read response
                string line;
                StreamReader input = new StreamReader(socket.GetStream());
                while ((line = input.ReadLine()) != null && line != string.Empty)
                    total += line + "/n";

                output.Close();
                socket.Close();
                return total;
            }
        }
开发者ID:Baptista,项目名称:PC,代码行数:26,代码来源:Program.cs

示例6: Connect

        public Boolean Connect(String ip, int port)
        {
            try
            {
                TcpClient = new System.Net.Sockets.TcpClient();
                TcpClient.ReceiveTimeout = 5000;
                TcpClient.SendTimeout = 5000;
                TcpClient.Connect(ip, port);
                Ns = TcpClient.GetStream();

                Bw = new BinaryWriter(TcpClient.GetStream());
                Br = new BinaryReader(TcpClient.GetStream());

                IsConnected = true;
            }
            catch (Exception e)
            {
                IsConnected = false;
                Log.Cl(e.Message);
                return false;
            }

            ReceptionThread = new Thread(new ThreadStart(Run));
            ReceptionThread.IsBackground = true;
            ReceptionThread.Start();

            return true;
        }
开发者ID:eickegao,项目名称:Blazera,代码行数:28,代码来源:ClientConnection.cs

示例7: TcpConnection

 public TcpConnection(TcpClient socket)
 {
     if (socket == null) throw new ArgumentNullException("socket");
     _socket = socket;
     _inputStream = new StreamReader(socket.GetStream());
     _outputStream = new StreamWriter(socket.GetStream());
 }
开发者ID:shariqkudcs,项目名称:openfastdotnet,代码行数:7,代码来源:TcpConnection.cs

示例8: Init

        public void Init(TcpClient tcpclient, int maxPackSize = 2048)
        {
            if (!tcpclient.Connected) throw new Exception("Must be connected");
            _tcpClient = tcpclient;

            base.Init(tcpclient.GetStream(), tcpclient.GetStream(), maxPackSize);
        }
开发者ID:KillerGoldFisch,项目名称:GCharp,代码行数:7,代码来源:GSocket.cs

示例9: Main

 static void Main(string[] args)
 {
     TcpClient cl = new TcpClient();
     IPEndPoint iep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9000);
     cl.Connect(iep);
     Console.WriteLine("Connected to Server!!!");
     //NetworkStream ns = new NetworkStream();
     StreamReader sr = new StreamReader(cl.GetStream());
     StreamWriter sw = new StreamWriter(cl.GetStream());
     string st = sr.ReadLine();
     Console.WriteLine("Server:{0}",st);
     while (true)
     {
         //string st;
         Console.Write("Nhap du lieu gui len Server:");
         st = Console.ReadLine();
         sw.WriteLine(st);
         sw.Flush();
         if (st.ToUpper().Equals("QUIT"))
             break;
         st = sr.ReadLine();
         Console.WriteLine("Data From Server:{0}", st);
     }
     sw.Close();
     sr.Close();
     cl.Close();
     //ns.Close();
 }
开发者ID:pthdnq,项目名称:csharp-project-nduang,代码行数:28,代码来源:Program.cs

示例10: UserConnectionToServer

        //method: UserConnectionToServer
        //description: initializes a new user connection to the server
        //params: Control owner - owner
        //        string server - server
        //        int port - port
        //        string userName - user's name/username
        //returns: void
        //throws ArgumentException and SocketException and IOException
        public UserConnectionToServer(Control owner, string server, int port, string userName)
        {
            this.owner = owner;

            //get name
            userName = userName.Trim();
            if(userName == "") {
                throw new ArgumentException("Name cannot be blank.", "userName");
            }

            //try to connect
            socket = new TcpClient(server, port);
            reader = new LinePeekableReader(new StreamReader(socket.GetStream()));
            writer = new StreamWriter(socket.GetStream());

            //identify as a user and provide name
            writer.WriteLine("user");
            writer.WriteLine(userName);
            writer.Flush();

            //start reading from server
            Thread thread = new Thread(ConnectionReader);
            thread.IsBackground = true;
            thread.Start();
        }
开发者ID:adam-currie,项目名称:WinProgAssign6,代码行数:33,代码来源:UserConnectionToServer.cs

示例11: RemoteProcessClient

        public RemoteProcessClient(string host, int port)
        {
            client = new TcpClient(host, port) {SendBufferSize = BufferSizeBytes, ReceiveBufferSize = BufferSizeBytes};

            reader = new BinaryReader(client.GetStream());
            writer = new BinaryWriter(client.GetStream());
        }
开发者ID:Evander83,项目名称:AICup-2013,代码行数:7,代码来源:RemoteProcessClient.cs

示例12: Initialize

        public override bool Initialize()
        {
            Logger.Log($"Connecting to Twitch IRC -> {Account.Username}");

            _Client = new TcpClient();
            _Client.ConnectAsync("irc.twitch.tv", 6667).Wait();

            _Writer = new StreamWriter(_Client.GetStream());
            _Reader = new StreamReader(_Client.GetStream());

            Logger.Log("Sending login credentials");

            _SendStringRaw($"PASS {Account.OAuth}");
            _SendStringRaw($"NICK {Account.Username}");

            var response = IRCMessage.Parse(_Reader.ReadLine());
            if (response.Type != "001")
            {
                Logger.Log("Server did not return expected login message");
                return false;
            }

            // runners
            new Thread(_SendRunner).Start();
            new Thread(_ReceiveRunner).Start();

            Logger.Log("Connecting to channels");
            foreach (var c in Channels)
                _SendString($"JOIN #{c}", MessagePriority.Medium);

            return true;
        }
开发者ID:Zogzer,项目名称:Applebot,代码行数:32,代码来源:TwitchConnection.cs

示例13: ConnectButton_Click

 private void ConnectButton_Click(object sender, EventArgs e)
 {
     if ((tcpClient == null) || (!tcpClient.Connected))
     {
         tcpClient = new TcpClient();
         try
         {
             MessageLabel.Text = "Connecting...";
             Application.DoEvents();
             tcpClient.Connect(TransportHostTextBox.Text, (int)TransportPortNumericUpDown.Value);
             streamWriter = new StreamWriter(tcpClient.GetStream());
             streamWriter.AutoFlush = true;
             streamReader = new StreamReader(tcpClient.GetStream());
             backgroundWorker.RunWorkerAsync();
             ConnectButton.Text = "Dis&connect";
             MessageLabel.Text = "Connected";
             TransportHostTextBox.Enabled = false;
             TransportPortNumericUpDown.Enabled = false;
             JabberIDTextBox.Enabled = false;
             Authenticated = false;
             skypeProxy.Command("GET CURRENTUSERHANDLE");
         }
         catch (SocketException ex)
         {
             MessageLabel.Text = ex.Message;
             tcpClient = null;
         }
     }
     else
     {
         backgroundWorker_RunWorkerCompleted(sender, null);
     }
 }
开发者ID:normanr,项目名称:skype-transport,代码行数:33,代码来源:SkypeJabberProxy.cs

示例14: StopIBController

        private static void StopIBController()
        {
            // Stop IBController if it's still running. IBController listens on a port
            // for three commands: STOP, EXIT, and ENABLEAPI. Here we send a STOP, then
            // an EXIT to cleanly shutdown TWS.
            try
            {
                byte[] stop = Encoding.Default.GetBytes("STOP\n");
                byte[] exit = Encoding.Default.GetBytes("EXIT\n");

                // connect to the IBController socket
                TcpClient tcp = new TcpClient(Settings.Default.IBControllerIp, Settings.Default.IBControllerPort);

                // send the "STOP" byte array to the IBController socket
                tcp.GetStream().Write(stop, 0, stop.Length);

                // send the "EXIT" command
                tcp.GetStream().Write(exit, 0, exit.Length);
            }
            catch (SocketException sockEx)
            {
                StringBuilder builder = new StringBuilder();
                builder.AppendFormat("IBController socket exeception: {0}\n", sockEx.Message);
                builder.AppendLine("Check the IP setting in IBController.ini,");
                builder.AppendLine("ensure it matches the setting in IBControllerService.config.");
                Logger.Instance.WriteError(builder.ToString());

                if (sockEx.InnerException != null)
                    Logger.Instance.WriteError("Inner Exception: {0}", sockEx.InnerException.Message);
            }
            catch (Exception ex)
            {
                Logger.Instance.WriteError(ex.Message);
            }
        }
开发者ID:rlktradewright,项目名称:ib-controller,代码行数:35,代码来源:IBControllerService.cs

示例15: Connect

        public void Connect(IPEndPoint endPoint, bool secure, bool rogue)
        {
            _connection = new TcpClient();

            _connection.Connect(endPoint);

            if (secure)
            {
                if (rogue)
                {
                    _stream = _connection.GetStream();

                    SendGarbage();
                }
                else
                {
                    var sslStream = new SslStream(_connection.GetStream(), false, (p1, p2, p3, p4) => true);

                    sslStream.AuthenticateAsClient(
                        "localhost",
                        null,
                        SslProtocols.Tls,
                        false
                    );

                    _stream = sslStream;
                }
            }
        }
开发者ID:pvginkel,项目名称:ProtoChannel,代码行数:29,代码来源:RogueClient.cs


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