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:
"
&
相关文档:
第一种
<%=RetInfo("DB","数据库") %>
<%=RetInfo("YX_UpFile","上传文件") %>
<%=RetfileInfo("Include/", "广告")%>
//从前台调用后台方法
//从前台调用后台的方法..并向其方法传入不同的参数!
第二种
<ItemTemplate >
<%#Ret_stat(Convert.ToInt16(Eval("YX_Stat1")), "热点")%>
......
public sealed class DbOper
{
///<summary>
/// DbOper类的构造函数
///</summary>
private DbOper()
{
}
......
大家在实际工作学习C#的时候,可能会问:为什么我们要为一些已经存在的功能(比如Windows中的一些功能,C++中已经编写好的一些方法)要重新编写代码,C#有没有方法可以直接都用这些原本已经存在的功能呢?答案是肯定的,大家可以通过C#中的DllImport直接调用这些功能。
DllImport所在的名字空间 using System.Runt ......
参考资料:http://wenwen.soso.com/z/q39607884.htm
如何在一个窗体中调用另一个窗体的控件或方法
答案是从构造函数中传递参数。
要把Form1中的控间改成public属性
具体实现过程请参看一下代码(在form2的textbox1中输入然后在form1中的label1中显示textbox中的内容
//form1代码,form1中有一个label1和一个button1,其 ......
private void save_db(){
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings[""].ToString());
SqlCommand comm = new SqlCommand();
conn.Open();
SqlTransaction rollbk2= conn.BeginTransaction();
& ......