客户端连接服务器c#network

时间:2013-06-13 22:00:56

标签: c# network-programming

IPAddress ip = new IPAddress(new byte[] (127,0,0,0));
TcpClient con = new TcpClient ();
con.Connect(ip,5020);
byte[] dtabfr;
dtabfr = Encoding.ASCII.GetBytes(textBox1.Text);
NetworkStream strm =con.GetStream();
strm.Write(dtabfr,0,dtabfr.Length);
strm.Close();
con.Close();

错误IPAddress ip数组创建必须具有数组大小或数组初始化程序

1 个答案:

答案 0 :(得分:2)

 IPAddress ip = new IPAddress(new byte[]{127,0,0,0});

或只是做

var ip = IpAddress.Parse("127.0.0.0");