alex Profesionist
Numarul mesajelor : 132 Varsta : 32 Location : Terra Data de inscriere : 20/10/2007
| Subiect: Multi connection port Joi Oct 25, 2007 8:49 pm | |
| Adaugatzi urmatoru modul - Cod:
-
Option Explicit Public Const ListenPort = 3535 Public Const ConnectionNr = 300 Public EmptyOrFull(ConnectionNr) As Boolean Public Function Accept() As Boolean On Error Resume Next Dim x As Integer For x = 1 To ConnectionNr Load frmMain.sock(x) Next x Accept = True Exit Function Accept = False End Function Public Function GetNew() As Integer On Error Resume Next Dim x As Integer For x = 1 To ConnectionNr If EmptyOrFull(x) = False Then GetNew = x Exit Function End If Next x GetNew = 0 End Function
Adaugatzi pe forma 2 winsockuri cu numele sock si sock2.Punetzi urmatorul cod pentru ele - Cod:
-
Private Sub sock2_ConnectionRequest(ByVal requestID As Long) Dim aFreeSocket As Integer aFreeSocket = GetNew If aFreeSocket = 0 Then sock(0).Accept requestID DoEvents sock(0).Close Else EmptyOrFull(aFreeSocket) = True sock(aFreeSocket).Accept requestID End If End Sub Private Sub sock_DataArrival(Index As Integer, ByVal bytesTotal As Long) Dim sData As String sock(Index).GetData sData End Sub Private Sub sock_Close(Index As Integer) EmptyOrFull(Index) = False End Sub
| |
|