同一个Socket, 连续发送2次,Receive就会报错
//create Socket
public void Connect()
{
if (Connected) return;
byte[] data = new byte[1024];
newclient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
//newclient.
string ipadd = "127.0.0.1";
int port = Convert.ToInt32("8888");
IPEndPoint ie = new IPEndPoint(IPAddress.Parse(ipadd), port);
try
{
newclient.Connect(ie);
Connected = true;
}
catch (SocketException e)
{
return;
}
}
//接收报文
public void ReceiveMsg()
{
bool bbl = false;
while (!bbl)
{
try
{
byte[] data = new byte[55296];
//同一个Socket, 连续发送2次,Receive就会报错:10053 An established connection was aborted by the software in your host mac
int recv = newclient.Receive(data);//
string stringdata = Encoding.GetEncoding("gb2312").GetString(data, 0, recv);
if (stringdata.Trim().Length > 0)
{
///////////读取报文回执///
//readerxml(stringdata);
sendtag = 0;//标记空闲
bbl = true;
}
}
catch
{
}
}
}
//发送报文
private void timer1_Tick(object sender, EventArgs e)
{
if (sendtag == 0)//标记空闲
{
if (tag < arrlist.Count)
{
sendtag = 1;//标记正在发送
String Msg = arrlist[tag].ToString();
if (Connected)
&n