演示:
Socket scoket=sock.Accept();
Byte[] bytes=new Byte[64];
string send="what the hell fuck this";
bytes=System.Text.Encoding.BigEndianUnicode.GetBytes(send.ToCharArray());
scoket.Send(bytes,bytes.length,0);//将byte数组全部发送
.NetWordStream类的Write方法发送数据
原型:public override void write(byte[] buffer,int offset,int size) 字节数组,开始字节位置,总字节数
Socket s=sock.Accept();
.NetWorkStream stre=new NewWorkStream(s);
Byte[] c=new Byte[512];
string sendmessage="what the hell fuck this";
c=System.Text.Encoding.BigEndianUnicode.GetBytes(sendmessage);
stre.Write(c,0,c.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 s=sock.Accept();
........
Byte[] byte=new Byte[512];
s.Receive(ccc,ccc.Length,0);
string rece=System.Text.Encoding.BigEndianUnicode.GetString(byte);
richTextBox1.AppendText(rece+"\r\n");
NetworkStream类的Read方法接收数据
public override int Read(int byte[] buffer,int offset,int size)
演示:b=sock.Accept();
.......
.NetworkStream stre=new.NetworkStream(b);
Byte[] c=new Byte[512];
stre.Read(c,0,ccc.Length);
string readMessage=System.Text.Encoding.BigEndianUnicode.GetString(c);
阅读(619) | 评论(0) | 转发(0) |