资源简介
使用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
相关资源
- C# Socket Server Client 通讯应用 完整的服
- C#TCP通信协议
- c# 高校档案信息管理系统
- C#TCP 通信(TCP发送16进制)
- C# Socket Tcp文件传输和文字聊天系统
- C# TCP通讯组件源代码
- C# TcpListener 例程(源码)
- C# Socket TCP通信
- c#实现Modbus tcp客户端
- c#与西门子s7-200 smart 通讯 S7TCPDLL.dll
- C# Modbus TCP通讯(S7200PLC)
- 使用Socket发送数据
- 服务器和客户端(TCP发送消息、发送
- TCP通信(支持发送文本和图片文件)
- 数据表转实体源码(实体类生成器)
- modbus tcp 调试
- kepserver 连接 PLC代码
- TcpClient C#2010读取PLC
- tcp和udp(Mina.net)
- Tcp/ip socket 服务器/客户端
- TCP/IP通讯 (附服务端以及客户端)
- ArcGIS MapServer 要素类
- IocpServer协议服务器
- 简单tcp 通讯网口工具客户端
- MODBUS通讯(TCP/Rtu)
- ASP.NET+SQL Server 2008 实现的学生学籍管
- asp.net中最好的对SQLSERVER数据库进行操
- C#+SQLServer文档管理系统
- asp.net+IIS+sqlserver选课系统毕业设计全
- 在线购物系统 C# ASP.NET SQL Server2005 毕
评论
共有 条评论