using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Net; using System.Net.Sockets;
namespace client { class class1
{ static void Main(string[] args) { try { int port = 2000; string host = "127.0.0.1"; IPAddress ip = IPAddress.Parse(host); IPEndPoint ipe = new IPEndPoint(ip,port);//把ip和端口转化为IPEndPoint实例 Socket c = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);//创建一个Socket Console.WriteLine("Conneting..."); c.Connect(ipe);//连接到服务器 string sendStr="hello!This is a socket test"; byte[] bs=Encoding.ASCII.GetBytes(sendStr);