www.pudn.com > CSNetServer.rar > Clientfrm.cs, change:2009-09-16,size:2040b


´╗┐using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
using System.Threading; 
using System.Diagnostics; 
using System.Net; 
using System.Net.Sockets; 
using System.IO; 
using System.Diagnostics; 
 
namespace CSNetClient 
{ 
    public partial class Clientfrm : Form 
    { 
        Thread t; 
        TcpClient client; 
        IPEndPoint endpoint; 
         
        public Clientfrm() 
        { 
            InitializeComponent(); 
            CheckForIllegalCrossThreadCalls = false; 
        } 
 
        private void button1_Click(object sender, EventArgs e) 
        { 
            endpoint = new IPEndPoint(IPAddress.Parse("192.168.1.26"), 8888); 
            client = new TcpClient(); 
            client.Connect(endpoint); 
            if (client.Connected) 
            { 
                t = new Thread(new ThreadStart(RunClient)); 
                t.Start(); 
                MessageBox.Show("ok"); 
            } 
        } 
         
        private void RunClient() 
        { 
            while (true) 
            { 
 
                NetworkStream netstream = client.GetStream(); 
                StreamReader sr = new StreamReader(netstream); 
                textBox1.Text +=Environment.NewLine+ sr.ReadLine(); 
            } 
        } 
 
        private void button2_Click(object sender, EventArgs e) 
        { 
            SendMessage(); 
        } 
        private void SendMessage() 
        { 
            try 
            { 
                StreamWriter sw = new StreamWriter(client.GetStream()); 
                sw.WriteLine(textBox2.Text); 
                sw.Flush(); 
            } 
            catch (Exception e) 
            { 
                MessageBox.Show(e.Message); 
            } 
        } 
 
        private void Form1_FormClosing(object sender, FormClosingEventArgs e) 
        { 
            Process.GetCurrentProcess().Kill(); 
        } 
    } 
}