0

我正在尝试开发一个通过套接字连接到 iSeries(as400 - PGM 程序)的类。连接工作正常,但是当我尝试发送和接收数据时出现错误。

这是代码:

class Program
{
    public static void StartClient()
    {
        byte[] bytes = new byte[1024];
        string desaip = "10.112.2.11";

        // Connect to a remote device.
        try
        {

            IPAddress[] ipAddress = Dns.GetHostAddresses(desaip);
            IPEndPoint remoteEP = new IPEndPoint(ipAddress[0], 42125);

            // Create a TCP/IP  socket.
            Socket sender = new Socket(AddressFamily.InterNetwork,
                SocketType.Stream, ProtocolType.Tcp);

            // Connect the socket to the remote endpoint. Catch any errors.
            try
            {
                sender.Connect(remoteEP);

                Console.WriteLine("Socket connected to {0}",
                    sender.RemoteEndPoint.ToString());


                #region forma A
                // Encode the data string into a byte array.
                byte[] msg = Encoding.ASCII.GetBytes("PRUEBAIB");


                // Send the data through the socket.
                int bytesSent = sender.Send(msg);

                // Receive the response from the remote device.
                sender.ReceiveTimeout = 10000;
                int bytesRec = sender.Receive(bytes);

                Console.WriteLine("Echoed test = {0}",
                    Encoding.ASCII.GetString(bytes, 0, bytesRec));

                // Release the socket.
                sender.Shutdown(SocketShutdown.Both);
                sender.Close();
                #endregion forma A


            }
            catch (ArgumentNullException ane)
            {
                Console.WriteLine("ArgumentNullException : {0}", ane.ToString());
            }
            catch (SocketException se)
            {
                Console.WriteLine("SocketException : {0}", se.ToString());
            }
            catch (Exception e)
            {
                Console.WriteLine("Unexpected exception : {0}", e.ToString());
            }

        }
        catch (Exception e)
        {
            Console.WriteLine(e.ToString());
        }
    }
}

有什么问题?

4

1 回答 1

0

检查应该在 iSeries 上侦听该端口的软件。确保它正在运行,它正在侦听该端口。使用该作业,并查看作业日志以查看发送了哪些消息。检查程序堆栈以查看它在哪个语句上,这可能有助于确定发生了什么。打开的文件和 I/O 统计信息也可能有所帮助。

于 2014-07-29T02:13:02.697 回答