C# 服务端
来源:互联网 发布:sql注入绕过安全狗 编辑:程序博客网 时间:2024/05/01 18:05
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Net;using System.Net.Sockets;using System.Threading;namespace 服务器端{ public partial class Form1 : Form { //字段声明 TcpListener tcpListener;//TCP监听 NetworkStream ns;//网络数据流 Thread listenThread;//监听线程 TcpClient tcpClient;//TCP客户 //回调 private delegate void ShowMsgCallBack(string msg); ShowMsgCallBack showMsgCallBack; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { showMsgCallBack = new ShowMsgCallBack(ShowMsg); } private void btnlisten_Click(object sender, EventArgs e) { IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Parse(txtIP.Text), Convert.ToInt32(txtPort.Text)); try { tcpListener = new TcpListener(ipEndPoint); tcpListener.Start(); listenThread = new Thread(listen); listenThread.IsBackground = true; listenThread.Start(); //修改按钮状态 btnlisten.Enabled = false; btnbreak.Enabled = true; btnSend.Enabled = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void listen() { try { tcpClient=tcpListener.AcceptTcpClient(); ns=tcpClient.GetStream(); while(true) { int reader=tcpClient.Available; if(reader>0) { byte []getDate=new byte[reader]; ns.Read(getDate,0,getDate.Length); string msg=Encoding.Default.GetString(getDate); lstMsg.Invoke(showMsgCallBack,msg); } } } catch (ThreadAbortException e) { //人为断开线程不用管 } catch (Exception e) { MessageBox.Show(e.Message); } } private void ShowMsg(string msg) { lstMsg.Items.Add(msg); } private void btnbreak_Click(object sender, EventArgs e) { tcpListener.Stop(); listenThread.Abort(); ns.Dispose(); //修改控件状态 btnbreak.Enabled = false; btnlisten.Enabled = true; btnSend.Enabled = false; } private void btnSend_Click(object sender, EventArgs e) { byte [] sendData = Encoding.Default.GetBytes(txtMsg.Text); ns.Write(sendData, 0, sendData.Length); } }}
0 0
- C# 服务端
- C#木马(服务端)
- C#服务端与客户端
- C# Socket服务端 案例
- C# 实现WebSocket服务端
- C# WebServices 客户端服务端
- C#处理服务端控件
- C# SuperSocket服务端入门
- C#服务端端口侦听浅析
- C#内存共享_服务端
- C# TCP Socket通信服务端
- c# Socket 异步客户端服务端
- c#上传文件到服务端
- C# 实现WebSocket服务端实例
- C# Socket编程 服务端与客户端(四) 异步服务端
- C# socket编程 异步服务端 同步客户端
- C#与Flash通信的服务端程序
- C#写木马服务端的开发
- PHP 函数漏洞总结
- bzoj3391
- 记录一下编译红米1s C/W (armani)Lineage OS的过程
- shell 中命令的文件比较功能
- 警惕一大波银行类木马正在靠近,新型BankBot木马解析
- C# 服务端
- 数据结构 day1
- 3D转换 导航栏
- hdu 1812 Count the Tetris (置换)
- Android平台Robotium UI测试详解
- 如何上传自己的代码到Git上
- [Aha]镖局运镖
- <32>python学习笔记——常用模块
- HBase 1.0.0 API的变化