连接到会话集成器的 LU0 会话时必须执行的第一个作是创建和初始化 Microsoft.HostIntegration.SNA.Session.SessionLU0
对象。 顾名思义, Microsoft.HostIntegration.SNA.Session.SessionLU0
表示应用程序的 LU0 会话,并且是用于访问 SNA 网络的主要接口。
初始化连接后,可以开始通过 LU0 会话发送和接收信息。
初始化 LU0 的会话集成器会话
确定要连接到的会话类型。
如有必要,请使用
Microsoft.HostIntegration.SNA.Session.SessionConnectionLU0
创建新的会话连接。如果拥有所有相关信息,则可以直接创建
Microsoft.HostIntegration.SNA.Session.SessionConnectionLU0
。 但是,无需执行此步骤。 很可能,你只需要在步骤 3 中传入 LU 连接字符串。使用
Microsoft.HostIntegration.SNA.Session.SessionLU0
.. 创建新会话。将连接信息传递给
Microsoft.HostIntegration.SNA.Session.SessionLU0.Connect%2A
。Connect
包含多个重载选项:可以选择与已创建的Microsoft.HostIntegration.SNA.Session.SessionConnection
对象进行连接,或者与Microsoft.HostIntegration.SNA.Session.SessionConnection
对象及其他初始化信息进行连接,或者使用连接字符串和初始化信息进行连接。如果选择通过连接字符串调用
Microsoft.HostIntegration.SNA.Session.SessionLU0.Connect%2A
,会话集成器将为你创建一个新的Microsoft.HostIntegration.SNA.Session.SessionConnectionLU0
。 可以通过Microsoft.HostIntegration.SNA.Session.SessionLU0.Connection%2A
直接访问Microsoft.HostIntegration.SNA.Session.SessionConnectionLU0
对象。如果需要,请确认您已连接并使用
Microsoft.HostIntegration.SNA.Session.SessionLU0.IsConnected%2A
。
示例:
下面的代码示例演示如何使用从用户收到的连接字符串创建会话。
private void CreateSession_Click(object sender, EventArgs e)
{
try
{
LUName.Text = LUName.Text.Trim();
if (LUName.Text.Length == 0)
{
MessageBox.Show("You must fill out the LU or Pool Name");
return;
}
_session = new SessionLU0(); _session.Connect("LogicalUnitName=" + LUName.Text, SessionLU0InitType.SSCP);
// Receive the logon screen.
SessionLU0Data receivedData = _session.Receive(20000, true);
// Trace out the received data.
TraceData(false, receivedData.Data, receivedData.Indication);
// Disable every button and text box.
DisableEverything();
// Insert User/Password.
EnableInsertUserId();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
请注意,此代码示例的主要用途是创建新的会话并使用连接字符串连接到 LU。 但是,该示例还接收通过 LU0 会话返回的数据。 该示例还使用 EnableInsertUserId
函数发送密码信息。