using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace AirbagSupportPackageService
{
public class LeafTCPClient
{
///
/// 当前客户端名称
///
private string _Name = "未定义";
public string Name
{
get
{
return _Name;
}
}
public void SetName()
{
if (_NetWork.Connected)
{
IPEndPoint iepR = (IPEndPoint)_NetWork.Client.RemoteEndPoint;
IPEndPoint iepL = (IPEndPoint)_NetWork.Client.LocalEndPoint;
//_Name = iepL.Port + "->" + iepR.ToString();
_Name = iepR.ToString();
}
}
///
/// TCP客户端
///
private TcpClient _NetWork = null;
public TcpClient NetWork
{
get
{
return _NetWork;
}
set
{
_NetWork = value;
SetName();
}
}
///
/// 数据接收缓存区
///
public byte[] buffer = new byte[1024];
///
/// 断开客户端连接
///
public void DisConnect()
{
try
{
if (_NetWork != null && _NetWork.Connected)
{
NetworkStream ns = _NetWork.GetStream();
ns.Close();
_NetWork.Close();
}
}
catch (Exception ex)
{
//MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}