All pastes #158805 Raw Edit

Something

public text v1 · immutable
·published 2006-09-02 08:48 UTC
rendered paste body
Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class frmIdentd
	Inherits System.Windows.Forms.Form
	Public Listening As Boolean
	
	Public Sub stopListening()
		On Error Resume Next
		logIdent("Stopped Listening")
		Socket.Close()
	End Sub
	
	Public Sub startListening()
		
		Timer1.Enabled = False
		Timer1.Interval = 60000
		
		On Error Resume Next
		With Socket
			'UPGRADE_NOTE: State was upgraded to CtlState. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
			If .CtlState <> MSWinsockLib.StateConstants.sckClosed Then .Close()
			.LocalPort = CInt(txtPort.Text)
			logIdent("Listening on port " & .LocalPort)
			.Listen()
		End With
	End Sub
	
	Private Sub cmdListen_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdListen.Click
		If Listening = False Then
			startListening()
			Listening = True
			cmdListen.Text = "S&top Listening"
		Else
			stopListening()
			Listening = False
			cmdListen.Text = "S&tart Listening"
		End If
	End Sub
	
	Private Sub socket_CloseEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles socket.CloseEvent
		logIdent("Remote closed connection")
		startListening()
	End Sub
	
	Private Sub socket_ConnectionRequest(ByVal eventSender As System.Object, ByVal eventArgs As AxMSWinsockLib.DMSWinsockControlEvents_ConnectionRequestEvent) Handles socket.ConnectionRequest
		With Socket
			'UPGRADE_NOTE: State was upgraded to CtlState. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
			If .CtlState <> MSWinsockLib.StateConstants.sckClosed Then .Close()
			.Accept(eventArgs.requestID)
			logIdent("Accept Connection from Client : " & .RemoteHost & " " & .RemoteHostIP & ":" & .RemotePort)
		End With
	End Sub
	
	Private Sub socket_DataArrival(ByVal eventSender As System.Object, ByVal eventArgs As AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent) Handles socket.DataArrival
		
		Dim buffer As String
		With Socket
			Timer1.Enabled = False
            .GetData(buffer)
			logIdent("Query : " & buffer)
			buffer = clearCRLF(buffer) & " : USERID : " & txtSystemId.Text & " : " & txtUserId.Text & vbCrLf
			logIdent("Answer: " & buffer)
			.SendData(buffer)
			Timer1.Enabled = True
		End With
		
	End Sub
	
	Private Sub Timer1_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Timer1.Tick
		stopListening()
		startListening()
	End Sub
	
	Private Sub logIdent(ByRef strDebug As String)
		Debug.Print(strDebug)
	End Sub
	
	Function clearCRLF(ByRef s As String) As String
		While VB.Right(s, 2) = vbCrLf
			s = VB.Left(s, Len(s) - 2)
		End While
		clearCRLF = s
	End Function

End Class