Probably a big taboo. This time only code, so add two sentences
 
Constructor that are implementing the policy pattern so I haven't had time to organize annotations recently
 
We'll see if we can make a statement later.
 
Code
 
Namespace communicate.tcp
Class Tcplinklistener
Inherits Global.WayneGameSolution.Communicate.LinkListener
Public Shared ReadOnly PropertyKeys as String () = {"Port", "Timeoutsecond", "linkprovestring"}
Public TcpListener as System.Net.Sockets.TcpListener
Private Clientlinkprovepool as New linkedlist (of Iclientlink)
Sub New (ByVal Parms as XElement)
MyBase.New (Parms)
Dim p as Int32
' TODO: various localized resources
Dim Notavailableproperties as IEnumerable (of String) = from key as String in PropertyKeys Select key Where not _PARMSDIC.C Ontainskey (Key)
If notavailableproperties.count > 0 Then
Throw New communicateexception (String.Format (My.Resources.Communicate_TCPLinkListener_Parms_Error_Message, String.Join (",", PropertyKeys), Propertykeys.length, String.Join (",", Notavailableproperties.toarray ()))
End If
If Port =-1 Then
Throw New communicateexception ((My.Resources.Communicate_TCPLinkListener_Parms_Port_Error_Message))
End If
If not Int32.TryParse (Port, p) Then
Throw New communicateexception ("no int port")
End If
TcpListener = New System.Net.Sockets.TcpListener (Net.IPAddress.Any, p)
Tcplistener.start ()
Tcplistener.beginacceptsocket (AddressOf tcplistener_acceptsocket, TcpListener)
End Sub
Sub Tcplistener_acceptsocket (ByVal o as IAsyncResult)
Checktimeoutedlinks ()
Dim socket as System.Net.Sockets.Socket = Tcplistener.endacceptsocket (o)
Dim CLK as New tcpclientlink (socket, Timeoutsecond, linkprovestring)
Clientlinkprovepool.addlast (CLK)
Tcplistener.beginacceptsocket (AddressOf tcplistener_acceptsocket, TcpListener)
End Sub
Private Sub checktimeoutedlinks ()
Dim LK as Tcpclientlink
Do While Clientlinkprovepool.count > 0
LK = Clientlinkprovepool.first (). Value
If LK. Lastdatatime.addseconds (Timeoutsecond) < now Then
Clientlinkprovepool.removefirst ()
If not LK. Islinkproved Then
Lk. Close ()
End If
Else
Exit do
End If
Loop
End Sub
ReadOnly Property Port () as Int32
Get
Dim p as Int32
If Int32.TryParse (Parmsdic ("Port"), p) Then
Return P
Else
Return-1
End If
End Get
End Property
ReadOnly Property Timeoutsecond () as Int32
Get
Dim T as Int32
If Int32.TryParse (Parmsdic ("Timeoutsecond"), T) Then
Return T
Else
Return-1
End If
End Get
End Property
ReadOnly Property linkprovestring () as String
Get
Return Parmsdic ("linkprovestring")
End Get
End Property
End Class
End Namespace