Game Hall starting from the base (3.5)--Client and server connection

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.