void btnSend_Click(object sender, EventArgs e)
...{
Socket sendSocket = new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
sendSocket.Connect("187.186.0.63", 8000);
byte[] buffer = Encoding.UTF8.GetBytes(textBox1.Text);
sendSocket.Send(buffer);
sendSocket.Shutdown(SocketShutdown.Both);
sendSocket.Close();
}
private void Form1_Load(object sender, EventArgs e)
...{
this.btnStartReceive.Enabled = true;
this.btnStopRecevie.Enabled = false;
}
}
}
Form.Designer.cs代码如下
namespace WinSocket
...{
partial class Form1
...{
/**//// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/**//// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">假如应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
...{
if (disposing && (components != null))
...{
components.Dispose();
}
base.Dispose(disposing);
}
Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码
/**//// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
...{
this.btnSend = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.btnStartReceive = new System.Windows.Forms.Button();
this.btnStopRecevie = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// btnSend
//
this.btnSend.Location = new System.Drawing.Point(164, 35);
this.btnSend.Name = "btnSend";
this.btnSend.Size = new System.Drawing.Size(75, 23);
this.btnSend.TabIndex = 0;
this.btnSend.Text = "发送";
this.btnSend.UseVisualStyleBackColor = true;
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(24, 37);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 21);
this.textBox1.TabIndex = 1;
//
评论加载中…
![]() |