我将 AxInterop.MSWinsockLib.dll 与 Interop.MSWinsockLib.dll 和 MSWINSCK.OCX 一起使用来创建到打印机的套接字连接。以下代码是我使用的,但无论我在尝试连接后将代码放入 while 循环还是 Thread.Sleep() 中,连接状态仍保持在 6,即“正在连接”。请尽快协助。
Try
Dim sock As AxMSWinsockLib.AxWinsock
sock = New AxMSWinsockLib.AxWinsock
CType(sock, System.ComponentModel.ISupportInitialize).BeginInit()
Me.Controls.Add(sock)
CType(sock, System.ComponentModel.ISupportInitialize).EndInit()
sock.RemoteHost = "10.194.1.132"
sock.RemotePort = 3001
sock.Connect()
MessageBox.Show(sock.CtlState.ToString())
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try