קבל:
WebForm1
Public Class WebForm1 Inherits System.Web.UI.Page #Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub #End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim mMSN As AdminiMessenger mMSN = CType(Session("admini_msn_object"), AdminiMessenger) Response.Write(Session("Status") & "<br>") 'response.Write(mmsn.w 'system.Web. End Sub End Class
המחלקה AdminiMessenger
Public Class AdminiMessenger Private WithEvents wsClient As New WinSock() Public Sub OpenSession(ByVal Email As String, ByVal Pass As String) sEmail = Email sPassword = Pass ConnectToMessenger() End Sub Public Sub ConnectToMessenger() SetStatus("Attempting connection to host messenger.hotmail.com...") wsClient.Connect("messenger.hotmail.com", 1863) WriteError("ws.Connect") ' messenger.hotmail.com -> 207.46.104.20 ' 207.46.107.37:1836 End Sub Private Sub wsClient_onConnect() Handles wsClient.onConnect bConnected = True WriteError("onConnect" & vbCrLf) End Sub End Class
WinSock מינימילי:
Public Class WinSock Public Event onConnect() Public Event onError(ByVal Description As String) Public Event onDataArrival(ByVal Data As Byte(), ByVal TotalBytes As Integer) Public Event onDisconnect() Public Event onSendComplete(ByVal DataSize As Integer) Private Shared response As [String] = [String].Empty Private Shared port As Integer = 44 Private Shared ipHostInfo As IPHostEntry = Dns.Resolve("localhost") Private Shared ipAddress As IPAddress = ipHostInfo.AddressList(0) Private Shared client As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) Public Shared NSTrial As Long Public Sub Connect(ByVal RemoteHostName As String, ByVal RemotePort As Integer) Try client = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) port = RemotePort ipHostInfo = Dns.Resolve(RemoteHostName) ipAddress = ipHostInfo.AddressList(0) Dim remoteEP As New IPEndPoint(ipAddress, port) client.BeginConnect(remoteEP, New AsyncCallback(AddressOf sockConnected), client) Catch RaiseEvent onError(Err.Description) Exit Sub End Try End Sub Private Sub sockConnected(ByVal ar As IAsyncResult) HttpContext.Current.Session("Status") += "Sock Connected" Try If client.Connected = False Then RaiseEvent onError("Connection refused.") : Exit Sub Dim state As New StateObject() state.workSocket = client client.BeginReceive(state.buffer, 0, state.BufferSize, 0, AddressOf sockDataArrival, state) RaiseEvent onConnect() Catch RaiseEvent onError(Err.Description) Exit Sub End Try End Sub End Class