日期:2014-05-17 浏览次数:20697 次
private delegate void ShowMsg(string strMsg);
private ShowMsg SM;
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
SM += new ShowMsg(SetLabel);
dt.Columns.Add("yvalue", typeof(string));
dt.Rows.Add();
}
private void SetLabel(string strMsg)
{
gvOpint.DataSource = dt;
gvOpint.DataBind();
}
protected void Button1_Click1(object sender, EventArgs e)
{
Sockelisten();
}
void Sockelisten()
{
IPAddress ips = Dns.GetHostAddresses(Dns.GetHostName())[0];
IPEndPoint ip = new IPEndPoint(IPAddress.Parse("192.168.2.59"), 6666);
Socket soc = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
soc.Bind(ip);
soc.Listen(10);
Socket hander = soc.Accept();
while (true)
{
byte[] bytes = new byte[1024];
int len = hander.Receive(bytes);
string st = Encoding.Default.GetString(bytes);
dt.Rows.Add();
dt.Rows[dt.Rows.Count - 1][0] = st;
GridView.Invoke(SM); //这一句代码在CS中是会报错的