110,534
社区成员
发帖
与我相关
我的任务
分享
this.hostIP = IPAddress.Parse(Dns.GetHostByName(Dns.GetHostName()).AddressList[0].ToString());
TcpListener listenner = new TcpListener(this.hostIP, 1127);
MessageBox.Show(hostIP.ToString());
listenner.Start();
Socket socket = listenner.AcceptSocket();
byte[] buff = new byte[100];
int count = socket.Receive(buff);
string str = "怎么把buff转换成string放在这里,谢谢啦";
MessageBox.Show(str);
ASCIIEncoding ascii = new ASCIIEncoding();
socket.Send(ascii.GetBytes("收到"));
string str = Encoding.ASCII.GetString(buff);
string strHost = this.hostIPtextBox.Text.ToString();
this.hostIP = IPAddress.Parse(strHost);
this.myIP = IPAddress.Parse(Dns.GetHostByName(Dns.GetHostName()).AddressList[0].ToString());
TcpClient tcpClient = new TcpClient();
tcpClient.Connect(strHost, 1127);
string str = "要传送的字符串";
Stream stm = tcpClient.GetStream();
ASCIIEncoding ascii = new ASCIIEncoding();
byte[] outBuff = ascii.GetBytes(str);
stm.Write(outBuff, 0, outBuff.Length);
byte[] inBuff = new byte[100];
int k = stm.Read(inBuff, 0, 100);
MessageBox.Show(inBuff.ToString());
this.Close();