⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 用c#实现类似qq的简单通讯程序.htm

📁 用c#实现类似QQ的简单通讯程序
💻 HTM
📖 第 1 页 / 共 4 页
字号:
            应用程序的主入口点。<BR>&nbsp; &nbsp; &nbsp; &nbsp; /// 
            &lt;/summary&gt;<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            [STAThread]<BR>&nbsp; &nbsp; &nbsp; &nbsp; static void Main() 
            <BR>&nbsp; &nbsp; &nbsp; &nbsp; {<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; Application.Run(new MainForm());<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; }<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            //开始监听<BR>&nbsp; &nbsp; &nbsp; &nbsp; private void 
            Listen()<BR>&nbsp; &nbsp; &nbsp; &nbsp; {<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; try<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; {<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; tcpLister.Start(); &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while(true)<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            Socket s = tcpLister.AcceptSocket();<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Byte[] stream = new 
            Byte[80];<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; int i = s.Receive(stream);<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            string message = 
            System.Text.Encoding.UTF8.GetString(stream);<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            this.txtRecord.AppendText(message); &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; 
            catch(System.Security.SecurityException)<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; {<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; 
            MessageBox.Show("防火墙安全错误!","错误",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; catch(System.Exception)<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            //this.txtRecord.AppendText("已停止监听!");<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; }<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            }<BR>&nbsp; &nbsp; &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            private void abortLister(object 
            sender,System.ComponentModel.CancelEventArgs e)<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; {<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            this.tcpLister.Stop();<BR>&nbsp; &nbsp; &nbsp; &nbsp; }<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; //发送<BR>&nbsp; &nbsp; &nbsp; &nbsp; private 
            void btnSend_Click(object sender, System.EventArgs e)<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; {<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; if(this.txtContent.Text=="")<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; {<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; 
            MessageBox.Show("不能发送空信息!","提示",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; else<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; {<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; this.Send();<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; }<BR>&nbsp; &nbsp; &nbsp; &nbsp; }<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; //发送消息<BR>&nbsp; &nbsp; &nbsp; &nbsp; private 
            void Send()<BR>&nbsp; &nbsp; &nbsp; &nbsp; {<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; try<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; {<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; string msg = this.txtName.Text+" 
            ("+System.DateTime.Now.ToString()+")\r\n"+this.txtContent.Text+"\r\n";<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TcpClient 
            client = new TcpClient(this.txtIp.Text,5566);<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NetworkStream 
            sendStream = client.GetStream();<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StreamWriter writer = new 
            StreamWriter(sendStream);<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; writer.Write(msg);<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            writer.Flush();<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; sendStream.Close();<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; client.Close();<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            this.txtRecord.AppendText(msg);<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            this.txtContent.Clear();<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; }<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            catch(System.Exception)<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; {<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; this.txtRecord.AppendText("目标计算机拒绝连接请求!\r\n");<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; }<BR>&nbsp; &nbsp; &nbsp; &nbsp; private void 
            MainForm_Load(object sender, System.EventArgs e)<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; {<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            this.txtRecord.AppendText("正在监听...\r\n"); &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; lister.Name = "监听本地端口";<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lister.Start();<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; }<BR>&nbsp; &nbsp; }<BR>}<BR>工程下载: <B></B><BR><A 
            href="http://mtv.blog.ccidnet.com/job.php?action=download&amp;pid=&amp;tid=18245&amp;aid=64" 
            target=_blank><FONT 
            color=red>Chat.rar</FONT></A><BR><BR></SPAN></DIV></TD></TR>
        <TR height=10>
          <TD bgColor=#bbd8e2><A class=content 
            href="http://mtv.blog.ccidnet.com/blog/ccid/do_showone/tid_18245.html">阅读全文(1300) 
            </A>| <A class=content 
            href="http://mtv.blog.ccidnet.com/blog/ccid/do_showone/tid_18245.html#comment">回复(1) 
            </A>| <A class=content title=将此文章推送到博友圈 
            href="http://mtv.blog.ccidnet.com/user.php?action=push&amp;tid=">推送</A> 
            | <A class=content title=如果您认为此文章含有反动或不雅的内容,请举报给管理员 
            onclick="window.open('http://blog.ccidnet.com/user.php?action=report&amp;tid=18245','report','top=60,left=300,width=410,height=390,resizable=0,scrollbars=no,status=0');" 
            href="javascript:">举报</A> </TD></TR>
        <TR>
          <TD align=right>&nbsp;</TD></TR>
        <TR>
          <TD bgColor=#bbd8e2>&nbsp; 共1条回复</TD></TR>
        <TR>
          <TD>
            <DIV class=comment 
            style="TABLE-LAYOUT: fixed; WORD-WRAP: break-word">
            <DIV>
            <DIV style="FLOAT: left"><I>guest 发表于 2006-02-08 12:46</I> </DIV>
            <DIV style="FLOAT: right"><I>#1</I> </DIV></DIV>
            <DIV class=clear></DIV><BR>
            <DIV class=content>thanks!</DIV>
            <DIV align=right><A href="javascript:scroll(0,0)">返回</A> 
            </DIV></DIV><BR>
            <DIV class=content></DIV></TD></TR></TBODY></TABLE>
      <TABLE class=content cellSpacing=0 cellPadding=3 width="95%" border=0>
        <TBODY>
        <TR>
          <TD>
            <FORM id=form1 name=form1 onsubmit="return commentcheck();" 
            action=comment.php? method=post><INPUT type=hidden value=comment 
            name=action> <INPUT type=hidden value=18245 name=tid> 
<B>发表评论</B><BR><TEXTAREA class=content name=content rows=11 cols=65></TEXTAREA> 
            <BR>验证码:<INPUT size=6 name=authnum> <IMG height=20 
            src="用c#实现类似QQ的简单通讯程序.files/authimg.png" align=absMiddle> 
            &nbsp;&nbsp;&nbsp;<INPUT type=image height=19 width=42 
            src="用c#实现类似QQ的简单通讯程序.files/1209-icon-21.gif" align=absMiddle 
            border=0 name=imageField22> </FORM><BR>
            <SCRIPT language=javascript>			function commentcheck()			{				if(document.form1.content.value == "")				{					alert("评论内容为空!");					document.form1.content.focus();					return false;				}				if(document.form1.authnum.value == "")				{						alert("验证码为空!");					document.form1.authnum.focus();					return false;				}				return true;			}			</SCRIPT>
          </TD></TR></TBODY></TABLE>
      <TABLE class=content cellSpacing=0 cellPadding=3 width="100%" border=0>
        <TBODY>
        <TR>
          <TD><BR><FONT color=#ff0000>※ 以上文章、评论纯属网友个人观点,本站不承担任何法律责任 <BR>※ 
            若发现该文章内容有问题,请 <A href="mailto:zhangxi@staff.ccidnet.com"><FONT 
            style="FONT-SIZE: 14px"><B>联系管理员</B></FONT></A> 
      </FONT></TD></TR></TBODY></TABLE></TD>
    <TD vAlign=top width=5><IMG height=3 
      src="用c#实现类似QQ的简单通讯程序.files/blank.gif" width=5></TD>
    <TD vAlign=top align=middle width=205 bgColor=#bbd8e2>
      <TABLE 
      style="BORDER-RIGHT: #bbd8e2 1px solid; BORDER-TOP: #bbd8e2 1px solid; BORDER-LEFT: #bbd8e2 1px solid; BORDER-BOTTOM: #bbd8e2 1px solid" 
      cellSpacing=0 cellPadding=5 width="100%" border=0>
        <TBODY>
        <TR>
          <TD align=middle>
            <TABLE class=content cellSpacing=0 cellPadding=1 width=190 
              border=0><TBODY>
              <TR>
                <TD align=middle><IMG height=137 
                  src="用c#实现类似QQ的简单通讯程序.files/3873_591949fcbb.jpg" 
              width=104></TD></TR>
              <TR>
                <TD align=middle><IMG height=5 
                  src="用c#实现类似QQ的简单通讯程序.files/1209-line-5.gif" width=190></TD></TR>
              <TR>
                <TD align=middle>lhuam 的BLOG</TD></TR>
              <TR>
                <TD align=middle><IMG height=5 
                  src="用c#实现类似QQ的简单通讯程序.files/1209-line-5.gif" 
              width=190></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
      <TABLE cellSpacing=0 cellPadding=0 width="100%" bgColor=#ffffff 
        border=0><TBODY>
        <TR>
          <TD><IMG height=5 src="用c#实现类似QQ的简单通讯程序.files/blank.gif" 
        width=20></TD></TR></TBODY></TABLE>
      <TABLE class=p9 height=29 cellSpacing=0 cellPadding=0 width="100%" 
      background=用c#实现类似QQ的简单通讯程序.files/1213_bar_4.gif border=0>
        <TBODY>
        <TR>
          <TD><IMG height=10 hspace=10 
            src="用c#实现类似QQ的简单通讯程序.files/1209-icon-4.gif" width=9 align=absMiddle 
            vspace=2><B>2006 6.5 Mon</B></TD></TR></TBODY></TABLE><IMG height=5 
      src="用c#实现类似QQ的简单通讯程序.files/blank.gif" width=20><BR>
      <TABLE class=side cellSpacing=0 cellPadding=0 width="100%" align=center 
      border=0>
        <TBODY>
        <TR>
          <TD class=side_center>日</TD>
          <TD class=side_center>一</TD>
          <TD class=side_center>二</TD>
          <TD class=side_center>三</TD>
          <TD class=side_center>四</TD>
          <TD class=side_center>五</TD>
          <TD class=side_center>六</TD></TR>
        <TR align=middle>
          <TD>&nbsp;</TD>
          <TD>&nbsp;</TD>
          <TD>&nbsp;</TD>
          <TD>&nbsp;</TD>
          <TD class=side_center>1</TD>
          <TD class=side_center>2</TD>
          <TD class=side_center>3</TD></TR>
        <TR align=middle>
          <TD class=side_center>4</TD>
          <TD class=side_center>5</TD>
          <TD class=side_center>6</TD>
          <TD class=side_center>7</TD>
          <TD class=side_center>8</TD>
          <TD class=side_center>9</TD>
          <TD class=side_center>10</TD></TR>
        <TR align=middle>
          <TD class=side_center>11</TD>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -