c# tcp调试助手源代码(19页).doc
《c# tcp调试助手源代码(19页).doc》由会员分享,可在线阅读,更多相关《c# tcp调试助手源代码(19页).doc(19页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、-c# tcp调试助手源代码-第 19 页 c# tcp 调试助手源代码以下是winform tcp 调试助手源代码,调试通过,可进行简单应用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.IO;using System.Net;
2、using System.Net.Sockets;using System.Threading;/using System.Timers;namespace TCP调獭?试?助手? public partial class Form1 : Form /*服务?端?*/ private int serve_portNum=13 ; private TcpListener serve_listener = null; /服务?器与?客户机之?间?的?连?接状痢?态? private bool bserve_Connected = false; /服务?器侦听瑈线?程 private Thread
3、tserve_AcceptMsg = null; /网?络?访?问的?基础?数簓据Y流? private NetworkStream nStream_serve = null; /创洹?建读取?器 private TextReader tReader_serve = null; /创洹?建编括?写器 private TextWriter wReader_serve = null; /*客户端?*/ private int Client_portNum = 13; /客户端?连?接 private TcpClient client_client = null; /客户机与?服务?器之?间?的?连
4、?接状痢?态? private bool bclient_Connected = false; /客户机侦听瑈线?程 private Thread tclient_AcceptMsg = null; /网?络?访?问的?基础?数簓据Y流? private NetworkStream nStream_client= null; /创洹?建读取?器 private TextReader tReader_client = null; /创洹?建编括?写器 private TextWriter wReader_client = null; /接收?、发?送数簓据Y池?长度 private const
5、int bytelength = 1024; /服务?器接收?池? byte serve_rec_buff = new bytebytelength; /服务?器发?送池? byte serve_send_buff = new bytebytelength; /客户端?接收?池? byte client_rec_buff = new bytebytelength; /客户端?发?送池? byte client_send_buff = new bytebytelength; public Form1() InitializeComponent(); rb_xs_zf.Checked = true
6、; rb_fs_zf.Checked = true; rb_fwq.Checked = true; cb_fs_cf.Checked = false; btn_Qidong.Enabled = false; /timer1=new System.Windows.Forms.Timer(); timer1.Stop(); timer2.Stop(); private void textBox1_TextChanged(object sender, EventArgs e) private void label2_Click(object sender, EventArgs e) private
7、void textBox1_TextChanged_1(object sender, EventArgs e) /服务?器启?动 private void Qidong_btn_Click(object sender, EventArgs e) serve_portNum = int.Parse(tbx_lport.Text); string strlocalip = cBox_localip.Text; IPAddress localaddr = null; localaddr = IPAddress.Parse(strlocalip); /listener = new TcpListene
8、r(strlocalip, serve_portNum); /IPAddress localaddr = host.AddressList0; /string ipAddress = host.AddressList0.ToString(); /tbx_Local_IP.Text = ipAddress; serve_listener = new TcpListener(localaddr, serve_portNum); lab_serve.Text = 服务?器正y在等台?待鋣连?接.; serve_listener.Start(); /创洹?建侦听瑈线?程 tserve_AcceptMs
9、g = new Thread(new ThreadStart(this.AcceptMessage); tserve_AcceptMsg.Start(); btn_Qidong.Enabled = false; /客户端?连?接服务?器 private void lianjie_btn_Click(object sender, EventArgs e) string hostName = tbx_serveIP.Text; Client_portNum = Convert.ToInt32(tbx_sport.Text); try client_client = new TcpClient(ho
10、stName, Client_portNum); if (client_client.Connected) /创洹?建侦听瑈线?程 tclient_AcceptMsg = new Thread(new ThreadStart(this.Client_AcceptMessage); tclient_AcceptMsg.Start(); btn_lianjie.Enabled = false; lab_client.Text = ok!?客户机连?接上?服务?器:阰 + hostName + ,?端?口号?:阰 + tbx_sport.Text; catch lab_client.Text = !
11、?客户机没?有瓺连?接上?服务?器:阰 + hostName + ,?端?口号?:阰 + tbx_sport.Text; /服务?器发?送字?符?数簓据Y public void serve_sendstr(string strsend) try /richTextBox2_KeyPress()和AcceptMessage() /都?将?向richTextBox1写字?符?,?可能访?问有瓺冲?突?,? /所以?,?需要癮多线?程互¥斥a lock (this) tx_serve_rec.AppendText(服务?器:阰 + strsend + n); /客户机聊?天?信?息写入?网?络?流
12、?,?以?便?服务?器接收? wReader_serve.WriteLine(strsend); /清?理?当獭?前缓o冲?区?数簓据Y,?使?所有瓺缓o冲?数簓据Y写入?基础?设?备? wReader_serve.Flush(); catch MessageBox.Show(无T法?与?客户机通?信?!); /服务?器发?送字?节数簓组哩?数簓据Y public void serve_sendhex(string InputString) #region 增?加字?符?处鋦理? string HexStrSplit = InputString.Split( ); int len = HexS
13、trSplit.Length; byte arr = new bytelen; for (int ii = 0; ii arr.Length; ii+) arrii = Convert.ToByte(HexStrSplitii, 16); string strtem = ; for (int ii = 0; ii arr.Length; ii+) strtem+= String.Format( 0x0:X2 , arrii); #endregion try /richTextBox2_KeyPress()和AcceptMessage() /都?将?向richTextBox1写字?符?,?可能访
14、?问有瓺冲?突?,? /所以?,?需要癮多线?程互¥斥a lock (this) tx_serve_rec.AppendText(服务?器:阰 + strtem + n); /客户机聊?天?信?息写入?网?络?流?,?以?便?服务?器接收? nStream_serve.Write(arr,0,arr.Length); /清?理?当獭?前缓o冲?区?数簓据Y,?使?所有瓺缓o冲?数簓据Y写入?基础?设?备? /nStream_serve.Flush(); catch MessageBox.Show(无T法?与?客户机通?信?!); /服务?器发?送数簓据Y private void button
15、1_Click(object sender, EventArgs e) if (bserve_Connected) if (cb_fs_cf.Checked = true) timer1.Stop(); timer1.Interval = Convert.ToInt32(tbx_fs_time.Text); timer1.Start(); else timer1.Stop(); if (rb_fs_zf.Checked = true) serve_sendstr(tx_serve_send.Text); else if (rb_fs_hex.Checked = true) serve_send
16、hex(tx_serve_send.Text); else MessageBox.Show(未与?客户机建立?连?接,?不?能通?信?。); /定时骸?发?送 private void ontime(object sender, EventArgs e) if (cb_fs_cf.Checked = true) if (rb_fs_zf.Checked = true) serve_sendstr(tx_serve_send.Text); else if (rb_fs_hex.Checked = true) serve_sendhex(tx_serve_send.Text); else time
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- c# tcp调试助手源代码19页 tcp 调试 助手 源代码 19
限制150内