` string ip = InitClass.ReadString("Jiguangji", "IP", ""); int port = 502;
if (InitClass.ReadString("Jiguangji", "Port", "") != "")
{
port = Convert.ToInt32(InitClass.ReadString("Jiguangji", "Port", ""));
}
try
{
//1,创建socket
Socket tcpClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
//2,发起建立连接的请求
** IPAddress ipaddress = IPAddress.Parse(ip); //可以把一个字符串的ip地址转化成一个ipaddress的对象**
EndPoint point = new IPEndPoint(ipaddress, port);
tcpClient.Connect(point); //通过ip:端口号 定位一个要连接到的服务器端
//发送模板给打印机`
来源:oschina
链接:https://my.oschina.net/xiaoxiezi/blog/3220682