System.IO.FileStream file = new FileStream("c:/a.txt",System.IO.FileMode.OpenOrCreate);
byte [] msg= new byte[file.Length];
file.Read(msg, 0, msg.Length );
System.Net.Sockets.Socket send = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork,System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
System.Net.IPEndPoint ipendp = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("127.0.0.1"), 9999);
send.Connect(ipendp);
send.Send(msg);
send.Shutdown(System.Net.Sockets.SocketShutdown.Both);
send.Close();
//发送端
System.IO.FileStream file = new FileStream("c:/b.txt", System.IO.FileMode.OpenOrCreate);
System.Net.Sockets.Socket soclip = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork,
System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
System.Net.IPEndPoint ipendp = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("127.0.0.1"), 9999);
soclip.Bind(ipendp);
soclip.Listen(100);
System.Net.Sockets.Socket soclipapp = soclip.Accept();
byte[] by = new byte[200];
string str = "";
soclipapp.Receive(by);
file.Write(by, 0, by.Length);//'将数据写到kk.txt中
file.Close();//'流关
str = System.Text.Encoding.UTF8.GetString(by);
soclipapp.Shutdown(System.Net.Sockets.SocketShutdown.Both);
soclipapp.Close();
Response.Write(str);
//接受,
//网上搜索,自己整理而来,名字我网了。在此表示谢谢
//运行此代码,建立两个工程。同时运行。这两个项目