资源简介
使用C#开发的 TCP SERVER 服务器,使用了多线程技术,从工作线程更新主线程的显示界面技术(委托)
代码片段和文件信息
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.Net;
using System.Threading;
using System.Net.Sockets;
using System.Collections;
namespace WindowsFormsApplicationTcpServer
{
public partial class Form1 : Form
{
// Socket array = new
int i=0;
Socket[] array1 = new Socket[50];
#region//定义变量
IPAddress HostIP = IPAddress.Parse(“127.0.0.1“);
IPEndPoint point;
Socket socket;
bool flag = true;
#endregion
#region//声明委托
delegate void SetTextCallback(string text);
public void SetText(string text)
{
textBox2.AppendText(text + “\r\n“);
}
delegate void SetTreeViewCallback(string text);
private void SetTreeView(string text)
{
// treeView1.BeginUpdate();
treeView1.Nodes[0].Nodes[0].Nodes.Add(text);
treeView1.Nodes[0].Nodes[0].Nodes[0].ImageIndex = 3;
treeView1.SelectedImageIndex = 3;
treeView1.ExpandAll();
// treeView1.EndUpdate();
}
#endregion
#region//进程方法
public void UpdateTextBox(string text)
{
this.Invoke(new SetTextCallback(SetText) new object[] { text });
}
class Work_Process
{
public Socket acceptedSocket;
public Form1 f;
public void Proccess()
{
if (acceptedSocket.Connected)
{
while (true)
{
byte[] receiveByte = new byte[64];
acceptedSocket.Receive(receiveByte receiveByte.Length 0);
string strInfo = Encoding.GetEncoding(51936).GetString(receiveByte);
f.UpdateTextBox(strInfo);
}
}
}
}
private void ProcessAccept()
{
while(flag)
{
try
{
Socket sk = socket.Accept();
Work_Process wkp = new Work_Process();
wkp.f = this;
wkp.acceptedSocket = sk;
array1[i] = sk;
i++;
this.Invoke(new SetTreeViewCallback(SetTreeView) new object[] { sk.Handle.ToString() });
Thread thread = new Thread(new ThreadStart(wkp.Proccess ));
thread.Start();
}
catch (Exception ey)
{
MessageBox.Show(ey.Message);
}
}
}
#endregion
public Form1()
{
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2013-02-27 20:29 WindowsFormsApplicationTcpServer\
目录 0 2013-03-09 12:08 WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer\
文件 187 2013-02-27 20:29 WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer\App.config
文件 9317 2013-03-14 15:51 WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer\Form1.Designer.cs
文件 7110 2013-03-14 16:05 WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer\Form1.cs
文件 11275 2013-03-14 15:51 WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer\Form1.resx
文件 544 2013-02-27 20:29 WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer\Program.cs
目录 0 2013-02-27 20:29 WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer\Properties\
文件 1402 2013-02-27 20:29 WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer\Properties\AssemblyInfo.cs
文件 2916 2013-02-27 20:29 WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer\Properties\Resources.Designer.cs
文件 5612 2013-02-27 20:29 WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer\Properties\Resources.resx
文件 1119 2013-02-27 20:29 WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer\Properties\Settings.Designer.cs
文件 249 2013-02-27 20:29 WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer\Properties\Settings.settings
文件 3843 2013-02-27 20:36 WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer.csproj
文件 953 2013-03-09 12:08 WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer.sln
文件 39424 2013-03-14 16:05 WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer.v11.suo
目录 0 2013-02-27 20:29 WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer\bin\
目录 0 2013-02-27 20:36 WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer\bin\Debug\
文件 19456 2013-03-14 16:05 WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer\bin\Debug\WindowsFormsApplicationTcpServer.exe
文件 187 2013-02-27 20:29 WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer\bin\Debug\WindowsFormsApplicationTcpServer.exe.config
文件 34304 2013-03-14 16:05 WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer\bin\Debug\WindowsFormsApplicationTcpServer.pdb
文件 22984 2013-03-14 16:05 WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer\bin\Debug\WindowsFormsApplicationTcpServer.vshost.exe
文件 187 2013-02-27 20:29 WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer\bin\Debug\WindowsFormsApplicationTcpServer.vshost.exe.config
文件 490 2012-06-06 02:06 WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer\bin\Debug\WindowsFormsApplicationTcpServer.vshost.exe.manifest
目录 0 2013-02-27 20:29 WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer\obj\
目录 0 2013-03-14 16:05 WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer\obj\Debug\
文件 1308 2013-03-02 09:11 WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer\obj\Debug\DesignTimeResolveAssemblyReferences.cache
文件 7099 2013-03-09 10:47 WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
目录 0 2013-03-23 17:01 WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer\obj\Debug\TempPE\
文件 0 2013-02-27 20:29 WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
文件 0 2013-02-27 20:29 WindowsFormsApplicationTcpServer\WindowsFormsApplicationTcpServer\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
............此处省略10个文件信息
- 上一篇:磁盘调度模拟---C#窗口化
- 下一篇:hadoop2.7.7@win64
相关资源
- ASP.NET+SQL Server 2008 实现的学生学籍管
- asp.net中最好的对SQLSERVER数据库进行操
- C#+SQLServer文档管理系统
- asp.net+IIS+sqlserver选课系统毕业设计全
- 在线购物系统 C# ASP.NET SQL Server2005 毕
- 基于.NET+sqlserver的简易微博
- 电子病历系统.rar
- SQLserver+C#实现的KTV点歌系统 有数据库
- 考勤系统(Asp.net+SQL Server)
- ASP.NET+SQL Server加油站管理系统.rar
- 教师信息管理系统ASP.NET+SQL Server2005,
- C# 使用 TcpClient,Socket 聊天
- 酒店管理系统C#基于vs2010源代码和SQ
- tcp+udp完全c#通信封装
- OPC UA Server .Net源码,SDK
- 基于ASP.NET零食销售网站源码
- Unity通过TCP接收服务端数据
- C#停车场管理系统的设计与实现VS201
- 健身俱乐部管理系统的设计与实现.
- 学生通讯录
- C#语言基于SQL server 的图书管理系统
- Unity和C#实现TCP网络聊天
- 基于ASP.NET的在线考试系统
- ASP.NET+SQL Server动态网站开发从基础到
- asp.net+Sql server实践项目源码
- 用C#实现的图书馆管理系统
- 基于ASP.NET学生请假管理系统源码
- Asp.net+SqlServer在线答题系统源码+数据
- ASP.NET/c# sql server 航空售票系统
- 旅游管理系统代码+设计文档
评论
共有 条评论