易截截图软件、单文件、免安装、纯绿色、仅160KB

C#的TCP通信


TCP是连接模型,如下:
服务器连接                     服务器断开
    ↓                                   ↑
服务器接收→服务器处理→服务器发送
    ↑                                   ↓
客户端发送←客户端处理←客户端接收
    ↑                                   ↓
客户端连接                     客户端断开
服务器代码如下:
//
ServerListen
TcpListener tcplistener
=
new
 TcpListener(
int
.Parse(txtPort.Text));
tcplistener.Start();
byte
[] btServerReceive
=
new
 
byte
[
256
];
string
 strServerReceive
=
string
.Empty;
//
Loop for Listen
while
(
true
)
{
 TcpClient tcp
=
tcplistener.AcceptTcpClient();
 NetworkStream ns
=
tcp.GetStream();
 
int
 intReceiveLength
=
 ns.Read(btServerReceive,
0
,btServerReceive.Length);
 strServerReceive
=
UnicodeEncoding.Unicode.GetString(btServerReceive,
0
,intReceiveLength);
 txtServerResult.AppendText(
"
ServerReceive:
"
 
+
 strServerReceive
+
"

"
);
 ns.Write(btServerReceive,
0
,btServerReceive.Length);
 txtServerResult.AppendText(
"
ServerSend:
"
&


相关文档:

c#(asp.net)几中不同从前台页面操作后台

第一种
<%=RetInfo("DB","数据库") %>
<%=RetInfo("YX_UpFile","上传文件") %>
<%=RetfileInfo("Include/", "广告")%>
//从前台调用后台方法
//从前台调用后台的方法..并向其方法传入不同的参数!
第二种
<ItemTemplate >
<%#Ret_stat(Convert.ToInt16(Eval("YX_Stat1")), "热点")%> ......

ASP.NET(C#)常用代码30例

1. 打开新的窗口并传送参数:
  传送参数:
response.write("<script>window.open(’*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="+...+"’)</script>")
  接收参数:
string a = Request.QueryString("id");
string b = Request.QueryString("id1");
  2.为按钮添加对话框
Button1 ......

C# 回滚

 private void save_db(){
    SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings[""].ToString());
    SqlCommand comm = new SqlCommand();
    conn.Open();
    SqlTransaction rollbk2= conn.BeginTransaction();
& ......

C# 回滚1

c#事务回滚(转)
作者:xue5ya  来源:博客园  发布时间:2009-03-20 16:08  阅读:263 次  原文链接   [收藏]  
Code
public void UpdateContactTableByDataSet(DataSet ds,string strTblName) 

    ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号