【问题标题】:TCP connection timeout error code _COMPlusExceptionCode -532462766TCP连接超时错误代码_COMPlusExceptionCode -532462766
【发布时间】:2013-12-27 13:29:34
【问题描述】:

我是 c# 中 TCP/IP 编程的新手,所以我非常渴望找到解决当前问题的方法!

我设计了一个在 Windows 7 下运行的 C# Windows 应用程序,带有 Sqlserver 2005 数据库。我的应用程序试图通过 TCP/IP 连接将 HL7 记录发送到 Unix 实验室。系统机器。

我可以连接正常,然后发送 HL7。但我无法从实验室得到任何答复。服务器!连接超时,错误代码为 10060,_COMPlusExceptionCode 值为 -532462766。

这是我的 c# 'Connect' 方法的示例:

   buildSendHL7_TCPIP hl7Agent = new buildSendHL7_TCPIP(); 

// 类 'buildSendHL7_TCPIP(); ' 包含构建 HL7 段的方法,以及通过 TCP 连接发送和接收消息的方法

   string strServerIPAddress = string.Empty;
   Int32 intSocketNo         = new Int32();
   bool sentOK               = false;

   /***********************************/
   /*Try send the HL7 to LIS-HORIZON...*/
   /***********************************/

   strServerIPAddress = "10.1.6.248";
   intSocketNo = 5910;

   sentOK = hl7Agent.SendHL7(strServerIPAddress, intSocketNo, strHL7_Record);
   if (!sentOK)
      {
          _strUIMessage = "*Error* HL7 Message NOT sent  to LIS!";
          opsMessageBox mb = new opsMessageBox(this);
          mb.ShowDialog();
          mb.Close();
          goto EndLabel;

       }

以下是我创建的用于建立 TCP 连接并将 HL7 发送到 LIS 服务器的方法:

public bool SendHL7(string strIPAddress, Int32 intSocket, string hl7message)
    {
        /* send the complete HL7 message to the server...*/
        int  port = (int)intSocket;
        IPAddress localAddr  = IPAddress.Parse(strIPAddress);


        try
        {
            // Add the leading & trailing character field-separator and CR  LineFeed' t.

            string llphl7message = null;
            llphl7message = "|";
            llphl7message += hl7message;
            llphl7message += Convert.ToChar(28).ToString();
            llphl7message += Convert.ToChar(13).ToString();

            // Get the size of the message that we have to send.
            Byte[] bytesToSend = Encoding.ASCII.GetBytes(llphl7message);
            Byte[] bytesReceived = new Byte[256];

            // Create a socket connection with the specified server and port.
            Socket s = ConnectSocket(localAddr, port);

            // If the socket could not get a connection, then return false.
            if (s == null)
                return false;

            // Send message to the server.

           s.Send(bytesToSend, bytesToSend.Length, 0);

            // Receive the response back
            int bytes = 0;
            s.ReceiveTimeout = 3000; /* 3 seconds wait before timeout */

            bytes = s.Receive(bytesReceived, bytesReceived.Length, 0); /*   IMEOUT occurs!!! */

            string page = Encoding.ASCII.GetString(bytesReceived, 0, bytes);
            s.Close();

            // Check to see if it was successful
            if (page.Contains("MSA|AA"))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        catch (SocketException e)
        {
            MessageBox.Show("SocketExecptionError:" + e);
            return false;
        }
    }

    private static Socket ConnectSocket(IPAddress server, int port)
    {
        Socket s = null;
        IPHostEntry hostEntry = null;

        // Get host related information.
        hostEntry = Dns.GetHostEntry(server);

        foreach (IPAddress address in hostEntry.AddressList)
        {
            IPEndPoint ipe = new IPEndPoint(address, port);
            Socket tempSocket = new Socket(ipe.AddressFamily,SocketType.Stream,ProtocolType.Tcp);

            tempSocket.Connect(ipe);

            if (tempSocket.Connected)
            {
                s = tempSocket;
                break;
            }
            else
            {
                continue;
            }
        }
        return s;
    }

有人告诉我,由于病毒问题,套接字 5910 在 Windows 7 中无法接收任何通信。这是真的?如果是这样,我尝试连接到我们网络 (PACS/RIS) 套接字 # 5556 上的另一台服务器。我收到相同的超时错误消息。

【问题讨论】:

    标签: c# sql-server sockets tcp


    【解决方案1】:

    该行为看起来服务器不理解您的请求/根据预期协议未将其识别为完整消息。

    据我所知,您正在发送一条 HL7 消息。我不知道这个协议,根据谷歌它可能是健康级别 7。我发现的例子是以一些文本开头,然后是 |作为分隔符。您的消息以 | 开头。可能有问题……

    所以你应该看看你发送的消息是否匹配协议定义。

    【讨论】:

    • 感谢您的 cmets Roland。根据我们的协议,HL7 消息块的格式似乎正确。我做了一些进一步的测试,似乎 'Socket' 方法的 'protocolOption' 参数有问题。我尝试过使用 IP、Tcp、IP4、IP6 等,但也没有任何乐趣!
    • 是什么让您认为问题出在协议选项中?由于您可以创建连接但没有得到答案,我认为协议中存在问题。您可以在服务器上调试/跟踪,还是有一个工作客户端来比较发送的消息与您的消息?
    • 问题解决了!我发送的 HL7 消息段在消息的开头没有强制性的“垂直标签”! :-)
    猜你喜欢
    • 2013-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多