C# 向iSeries套接字(AS400)C发送和接收数据#
我正在尝试开发一个通过套接字连接到iSeries(as400-PGM程序)的类。连接工作正常,但当我尝试发送和接收数据时,会出现错误 代码如下:C# 向iSeries套接字(AS400)C发送和接收数据#,c#,sockets,ibm-midrange,pgm-protocol,C#,Sockets,Ibm Midrange,Pgm Protocol,我正在尝试开发一个通过套接字连接到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.
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统计数据也可能会有所帮助。您确定要在套接字级别实现此功能吗?肯定有一个图书馆可以提取这些?如果您需要这方面的帮助,您应该显示收到的实际错误。实际上,程序在等待响应时会被卡住。iSeries(或Power上的IBM i)服务器上的哪个软件正在侦听该端口?您是否检查了该程序是否处于活动状态并正在收听?您是否与安全管理员确认没有防火墙阻止您?若要添加到@CodeCaster answer,取决于您试图完成的任务,您甚至可能会发现,对于不频繁或低容量的事务,使用FTP这样简单的东西更容易——如果您正在发送要处理的数据,甚至可以在AS400上调用远程程序。听起来很古老,可能有更优雅的解决方案,但它可以非常可靠地工作。。。同样,这取决于您试图解决的问题以及您可以花费的时间。
…当我尝试发送和接收数据时,它会出错。
什么会出错?什么错误?什么声明?即使不知道“错误”是什么,也很难解决它。插座的另一端发生了什么?收到什么了吗?对吗?有什么东西寄出去了吗?它是否按预期到达?