跳转到内容
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
-
- using System.Net;
- using System.Net.Sockets;
-
- namespace WinNet
- {
- public partial class ClientFrm : Form
- {
- public ClientFrm()
- {
- InitializeComponent();
- }
-
- private void ClientFrm_Load(object sender, EventArgs e)
- {
-
- TcpClient tcpClient = new TcpClient();
-
- IPHostEntry host = Dns.GetHostEntry(“127.0.0.1”);
- tcpClient.Connect(host.AddressList[0], 8888);
-
- NetworkStream clientStream = tcpClient.GetStream();
-
- byte[] response = new byte[10];
- response = System.Text.Encoding.ASCII.GetBytes(“helloserve”.ToCharArray());
-
- clientStream.Write(response, 0, 10);
-
- clientStream.Read(response, 0, 10);
- this.Text = System.Text.Encoding.ASCII.GetString(response);
-
- tcpClient.Close();
- clientStream.Close();
- }
- }
- }