2007-03-21

C#实现Socket传输简单数据

来源: 本站收集整理 作者:佚名 评论 0 条
 
}

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;
//
共3页: 上一页 [1] 2 [3] 下一页

(本文仅表明作者个人观点,不代表本站及其管理员立场.) 推荐 收藏 投稿 打印 返回 关闭
上一篇:jsp中的数据库编程  
下一篇:JSP MySQL 无法插入中文问题(Data too long ...)
    评论加载中…
 推荐文章
     

网站首页  -  网站地图 -   站长论坛  -  网站投稿  -    -  网站管理
Copyright © 2008 芜湖站长站 All Rights Reserved 皖ICP备07500611号