原型三:public int Send(byte[],int,SocketFlags) 參數二要發送的字節數
原型四:public int Send(byte[],int,int,SocketFlags) 參數二為Byte[]中開始發送的位置
演示:
Socket bbb=sock.Accept();
Byte[] bytes=new Byte[64];
string send="aaaaaaaaaaaa";
bytes=System.Text.Encoding.BigEndianUnicode.GetBytes (send.ToCharArray());
bbb.Send(bytes,bytes.length,0);//將byte數組全部發送
.NetWordStream類的Write方法發送數據
原型:public override void write(byte[] buffer,int offset,int size) 字節數組,開始字節位 置,總字節數
Socket bbb=sock.Accept();
.NetWorkStream stre=new NewWorkStream (bbb);
Byte[] ccc=new Byte[512];
string sendmessage="aaaaaaaaaaaaaa";
ccc=System.Text.Encoding.BigEndianUnicode.GetBytes (sendmessage);
stre.Write(ccc,0,ccc.length);
接收數據:Socket類Receive.NetworkStream類Read
Socket類Receive方法
原型:public int Receive(byte[] buffer)
2)public int Receive(byte[],SocketFlags)
3)public int Receive(byte [],int,SocketFlags)
4)public int Receive(byte[],int,int,SocketFlags)
.....
Socket bbb=sock.Accept();
........
Byte[] ccc=new Byte [512];
bbb.Receive(ccc,ccc.Length,0);
string rece=System.Text.Encoding.BigEndianUnicode.GetString(ccc);
richTextBox1.AppendText(rece+"\r\n");
.NetworkStream類的Read方法接收數據
public override int Read(int byte[] buffer,int offset,int size)
演示:bbb=sock.Accept();
.......
.NetworkStream stre=new.NetworkStream(bbb);
Byte[] ccc=new Byte[512];
stre.Read(ccc,0,ccc.Length);
string readMessage=System.Text.Encoding.BigEndianUnicode.GetString(ccc);