日期:2014-05-17 浏览次数:21058 次
public void backConnect( IPAddress backIP,int backPort,string negativeID)
{
try
{
TcpClient tcp = new TcpClient();//申明tcp客户端
tcp.Connect(backIP,backPort);//连接tcp
Thread.Sleep(1000);// 延时操作
if (tcp != null)
{
formDboper.listboxDboper.Items.Add("返回标示字TCP连接" + backIP + "成功!");
formDboper.listboxDboper.TopIndex = formDboper.listboxDboper.Items.Count - 1;//顶端显示最后一行
ns = tcp.GetStream();
Byte[] sendBytes = Encoding.ASCII.GetBytes(negativeID);//将negativeID以ASCII形式编码成Bytes类型的字节流数组
ns.Write(sendBytes, 0, sendBytes.Length);
formDboper.listboxDboper.Items.Add("标示字"+negativeID+"已返回!");
formDboper.listboxDboper.TopIndex = formDboper.listboxDboper.Items.Count - 1;//顶端显示最后一行
ns.Flush();
ns.Close();
}