c# IP打印

System.Net.Sockets.Socket s = null;

IPEndPoint hostEndPoint = new IPEndPoint(IPAddress.Parse(txtIP .Text .ToString ().Trim ()), Convert.ToInt32("9100"));

s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

s.Connect(hostEndPoint);

if (!s.Connected)

{

     MessageBox.Show("Not Connected");

}

else

{

     StreamReader sr1 = new StreamReader(@"C:\NEOLabel\TmpPalletLabel.txt", Encoding.UTF8);

     string strlabel = sr1.ReadToEnd();

     sr1.Close();

Byte[] data = Encoding.UTF8.GetBytes(strlabel);

     s.Send(data, data.Length, 0);       //发送数据文件

     if (s.Connected)

     s.Close();

}

System.Threading.Thread.Sleep(1500);

posted @ 2012-06-21 14:36  KingNiu  阅读(434)  评论(0编辑  收藏  举报