|
亿众国际点对点文件传输程序(25) using System; using System.net; using System.net.Sockets; using System.Windows.Forms; namespace CommonModule { /// <summary> /// Class1 的摘要说明。 /// </summary> public class EzoneModule { public EzoneModule() { // // TODO: 在此处添加构造函数逻辑 // } public static int SendData(Socket s,byte[] data) { int total=0; int size=data.Length; int dataleft=size; int sent; while(total<size) { sent=s.Send(data,total,dataleft,SocketFlags.None); total+=sent; dataleft-=sent; } return total; } public static byte[] ReceiveData(Socket s,int size) { int total=0; int dataleft=size; byte[] data=new byte[size]; int recv; while(total<size) { recv=s.Receive(data,total,dataleft,SocketFlags.None); if(recv==0) { data=null; break; } total+=recv; dataleft-=recv; } return data; } public static int SendVarData(Socket s,byte[] data) { int total=0; int size=data.Length;
|