[英]Send and Receive Data to iSeries Socket (AS400) C#
我正在嘗試開發一個通過套接字連接到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());
}
}
}
有什么事嗎
檢查應該在iSeries上監聽該端口的軟件。 確保它正在運行,正在偵聽該端口。 處理該作業,然后查看作業日志以查看發送了哪些消息。 檢查程序堆棧以查看其上的語句,這可能有助於確定發生了什么。 打開的文件和I / O統計信息也可能會有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.