客户端代码
代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Net;
using System.Threading;
using System.Net.Sockets;
namespace W.Common
{
public class CacheSocket
{
public Socket skClient;
public string ip = string.Empty;
public int port = -1;
public int netID;
// public int timeSleep = 1;
//每次接收发送的临时信息
private byte[] sendData;//发送的信息
private byte[] receiveData = new byte[1024];//接收信息
private int receiveN;
private bool isErr = false;
//--------
public CacheSocket(int pNetID)
{
this.netID = pNetID;
GetConfig();
Connection();
Cmd("netid:" + this.netID);
}
public CacheSocket(int pNetID, string pIP, int pPort)
{
this.ip = pIP;
this.port = pPort;
Connection();
Cmd("netid:" + pNetID);
}
public string Cmd(string key)
{
lock (this)//一个信息发送后再接收为一次完成过程
{
this.sendData = Encoding.UTF8.GetBytes(key);
try
{
新闻热点
疑难解答
图片精选