?? 用c#實(shí)現(xiàn)類似qq的簡(jiǎn)單通訊程序.htm
字號(hào):
應(yīng)用程序的主入口點(diǎn)。<BR> ///
</summary><BR>
[STAThread]<BR> static void Main()
<BR> {<BR>
Application.Run(new MainForm());<BR>
}<BR>
//開(kāi)始監(jiān)聽(tīng)<BR> private void
Listen()<BR> {<BR>
try<BR>
{<BR>
tcpLister.Start();
<BR>
while(true)<BR>
{<BR>
Socket s = tcpLister.AcceptSocket();<BR>
Byte[] stream = new
Byte[80];<BR>
int i = s.Receive(stream);<BR>
string message =
System.Text.Encoding.UTF8.GetString(stream);<BR>
this.txtRecord.AppendText(message);
<BR>
}
<BR>
}<BR>
catch(System.Security.SecurityException)<BR>
{<BR>
MessageBox.Show("防火墻安全錯(cuò)誤!","錯(cuò)誤",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);<BR>
}<BR>
catch(System.Exception)<BR>
{<BR>
//this.txtRecord.AppendText("已停止監(jiān)聽(tīng)!");<BR>
}<BR>
}<BR> <BR>
private void abortLister(object
sender,System.ComponentModel.CancelEventArgs e)<BR>
{<BR>
this.tcpLister.Stop();<BR> }<BR>
//發(fā)送<BR> private
void btnSend_Click(object sender, System.EventArgs e)<BR>
{<BR>
if(this.txtContent.Text=="")<BR>
{<BR>
MessageBox.Show("不能發(fā)送空信息!","提示",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);<BR>
}<BR>
else<BR>
{<BR>
this.Send();<BR>
}<BR> }<BR>
//發(fā)送消息<BR> private
void Send()<BR> {<BR>
try<BR>
{<BR>
string msg = this.txtName.Text+"
("+System.DateTime.Now.ToString()+")\r\n"+this.txtContent.Text+"\r\n";<BR>
TcpClient
client = new TcpClient(this.txtIp.Text,5566);<BR>
NetworkStream
sendStream = client.GetStream();<BR>
StreamWriter writer = new
StreamWriter(sendStream);<BR>
writer.Write(msg);<BR>
writer.Flush();<BR>
sendStream.Close();<BR>
client.Close();<BR>
this.txtRecord.AppendText(msg);<BR>
this.txtContent.Clear();<BR>
}<BR>
catch(System.Exception)<BR>
{<BR>
this.txtRecord.AppendText("目標(biāo)計(jì)算機(jī)拒絕連接請(qǐng)求!\r\n");<BR>
}<BR>
}<BR> private void
MainForm_Load(object sender, System.EventArgs e)<BR>
{<BR>
this.txtRecord.AppendText("正在監(jiān)聽(tīng)...\r\n");
<BR>
lister.Name = "監(jiān)聽(tīng)本地端口";<BR>
lister.Start();<BR>
}<BR> }<BR>}<BR>工程下載: <B></B><BR><A
href="http://mtv.blog.ccidnet.com/job.php?action=download&pid=&tid=18245&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">回復(fù)(1)
</A>| <A class=content title=將此文章推送到博友圈
href="http://mtv.blog.ccidnet.com/user.php?action=push&tid=">推送</A>
| <A class=content title=如果您認(rèn)為此文章含有反動(dòng)或不雅的內(nèi)容,請(qǐng)舉報(bào)給管理員
onclick="window.open('http://blog.ccidnet.com/user.php?action=report&tid=18245','report','top=60,left=300,width=410,height=390,resizable=0,scrollbars=no,status=0');"
href="javascript:">舉報(bào)</A> </TD></TR>
<TR>
<TD align=right> </TD></TR>
<TR>
<TD bgColor=#bbd8e2> 共1條回復(fù)</TD></TR>
<TR>
<TD>
<DIV class=comment
style="TABLE-LAYOUT: fixed; WORD-WRAP: break-word">
<DIV>
<DIV style="FLOAT: left"><I>guest 發(fā)表于 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>發(fā)表評(píng)論</B><BR><TEXTAREA class=content name=content rows=11 cols=65></TEXTAREA>
<BR>驗(yàn)證碼:<INPUT size=6 name=authnum> <IMG height=20
src="用c#實(shí)現(xiàn)類似QQ的簡(jiǎn)單通訊程序.files/authimg.png" align=absMiddle>
<INPUT type=image height=19 width=42
src="用c#實(shí)現(xiàn)類似QQ的簡(jiǎn)單通訊程序.files/1209-icon-21.gif" align=absMiddle
border=0 name=imageField22> </FORM><BR>
<SCRIPT language=javascript> function commentcheck() { if(document.form1.content.value == "") { alert("評(píng)論內(nèi)容為空!"); document.form1.content.focus(); return false; } if(document.form1.authnum.value == "") { alert("驗(yàn)證碼為空!"); 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>※ 以上文章、評(píng)論純屬網(wǎng)友個(gè)人觀點(diǎn),本站不承擔(dān)任何法律責(zé)任 <BR>※
若發(fā)現(xiàn)該文章內(nèi)容有問(wèn)題,請(qǐng) <A href="mailto:zhangxi@staff.ccidnet.com"><FONT
style="FONT-SIZE: 14px"><B>聯(lián)系管理員</B></FONT></A>
</FONT></TD></TR></TBODY></TABLE></TD>
<TD vAlign=top width=5><IMG height=3
src="用c#實(shí)現(xiàn)類似QQ的簡(jiǎn)單通訊程序.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#實(shí)現(xiàn)類似QQ的簡(jiǎn)單通訊程序.files/3873_591949fcbb.jpg"
width=104></TD></TR>
<TR>
<TD align=middle><IMG height=5
src="用c#實(shí)現(xiàn)類似QQ的簡(jiǎn)單通訊程序.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#實(shí)現(xiàn)類似QQ的簡(jiǎn)單通訊程序.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#實(shí)現(xiàn)類似QQ的簡(jiǎn)單通訊程序.files/blank.gif"
width=20></TD></TR></TBODY></TABLE>
<TABLE class=p9 height=29 cellSpacing=0 cellPadding=0 width="100%"
background=用c#實(shí)現(xiàn)類似QQ的簡(jiǎn)單通訊程序.files/1213_bar_4.gif border=0>
<TBODY>
<TR>
<TD><IMG height=10 hspace=10
src="用c#實(shí)現(xiàn)類似QQ的簡(jiǎn)單通訊程序.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#實(shí)現(xiàn)類似QQ的簡(jiǎn)單通訊程序.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> </TD>
<TD> </TD>
<TD> </TD>
<TD> </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>
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -