已建立的连接已被主机中的软件中止

时间:2016-01-29 07:24:38

标签: c# sockets

希望修复此错误 远程主机强制关闭现有连接 已建立的连接已被主机中的软件中止

try
{
    while (this.remote)
    {
        if (!this.remote)
            break;

        this.lg_remote_recv_buffer.Offset = 0;
        SocketError socketError;
        this.lg_remote_recv_buffer.Size = this.lg_remote_client.Receive(this.lg_remote_recv_buffer.Buffer, 0, this.lg_remote_recv_buffer.Buffer.Length, SocketFlags.None, out socketError);
        if (socketError != SocketError.Success)
        {
            if (socketError != SocketError.WouldBlock)
            {
                this.CleanClient();
                break;
            }
        }
        else
        {
            if (!this.lg_remote_client.Connected || this.lg_remote_recv_buffer.Size <= 0)
            {
                this.CleanClient();
                break;
            }
            this.lg_remote_security.Recv(this.lg_remote_recv_buffer);
        }
        this.lg_remote_recv_packets = this.lg_remote_security.TransferIncoming();
        if (this.lg_remote_recv_packets != null)
        {
            foreach (Packet packet in this.lg_remote_recv_packets)
            {
                if (!this.remote)
                    break;
                if (gameremotescanpackets.Contains(packet.Opcode))
                {
                    byte[] bytes = packet.GetBytes();
                    if (packet.Opcode != 20480 && packet.Opcode != 36864)
                    {
                        if (packet.Opcode == 12416)
                        {
                            int num2 = (int)packet.ReadUInt8();
                            if (num2 == 2 || num2 == 3)
                            {
                                uint num3 = packet.ReadUInt32();
                                foreach (ClientsGame current in Form1.clientlistgame)
                                {
                                    if (Form1.banlistesi.Contains(this.ip.ToString()))
                                        break;

                                    if (current.lg_local_client.Connected && current.lg_remote_client.Connected) //VSRO SHIT /* && current.UniqueID == num3*/
                                    {
                                        this.party_sender = current;
                                        //Globals.MainWindow.MessagesLogs("someone intived party !"); ** Useless shit pls clear that system really yusl q xd
                                        break;
                                    }
                                }
                            }
                        }
                        this.lg_local_security.Send(packet);
                    }
                }
                else
                {
                    this.lg_local_security.Send(packet);
                }
            }
        }
        this.lg_remote_send_buffers = this.lg_remote_security.TransferOutgoing();
        if (this.lg_remote_send_buffers != null)
        {
            foreach (KeyValuePair<TransferBuffer, Packet> current2 in this.lg_remote_send_buffers)
            {
                if (!this.remote)
                    break;

                Packet packet = current2.Value;
                TransferBuffer key = current2.Key;
                while (key.Offset != key.Size)
                {
                    if (!this.remote)
                        break;

                    try
                    {
                        this.lg_remote_client.Blocking = true;
                        int num6 = this.lg_remote_client.Send(key.Buffer, key.Offset, key.Size - key.Offset, SocketFlags.None);
                        this.lg_remote_client.Blocking = false;
                        key.Offset += num6;
                    }
                    catch { }
                }
                byte[] bytes = packet.GetBytes();
            }
        }
        Thread.Sleep(4);
    }
}
catch
{
    CleanClient();
}

0 个答案:

没有答案