Write to a NetworkStream : NetworkStream « Network « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Network » NetworkStreamScreenshots 
Write to a NetworkStream
 
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Net.Sockets;


class Program {
    static void Main(string[] args) {
        TcpClient client = new TcpClient();
        IPHostEntry host = Dns.GetHostByName("www.google.com");
        client.Connect(host.AddressList[0]8000);

        NetworkStream clientStream = client.GetStream();

        string request = "LIST";
        byte[] requestBuffer = Encoding.ASCII.GetBytes(request);
        clientStream.Write(requestBuffer, 0, requestBuffer.Length);

        byte[] responseBuffer = new byte[256];
        MemoryStream memStream = new MemoryStream();
        int bytesRead = 0;
        do {
            bytesRead = clientStream.Read(responseBuffer, 0256);
            memStream.Write(responseBuffer, 0, bytesRead);
        while (bytesRead > 0);



    }
}

 
Related examples in the same category
1.implements a NetworkStream server
2.implements a NetworkStream client 2
3.Acts as a server program to demonstrate the use of the NetworkStream classActs as a server program to demonstrate the use of the NetworkStream class
4.Acts as a client program to demonstrate the use of the NetworkStream classActs as a client program to demonstrate the use of the NetworkStream class
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.