Miren ya tengo el método de como hacer para que se puedan conectar múltiples clientes a mi servidor: publicare el código fuente, ya que es ejemplo de una web:
Todos los que ayuden y aporten para este proyecto saldrán en Agradecimientos, pero sobre todo estaré agradecido yo.
Cliente:
Código:
Imagen Cliente: Private Sub CommandXP1_Click() Winsock1.SendData Text2.Text & vbCrLf Text1.SelStart = Len(Text1.Text) Text1.Text = Text1.Text & "Cliente >" & Text2.Text & vbCrLf Text1.SelStart = Len(Text1.Text) Text2.Text = "" End Sub Private Sub CommandXP2_Click() Winsock1.RemoteHost = Text3.Text Winsock1.RemotePort = Text4.Text Winsock1.Close Winsock1.Connect End Sub Private Sub CommandXP3_Click() 'cierra la conexion Winsock1.Close 'desplegamos un mensaje en la ventana Text1.Text = Text1.Text & "*** Conexion cerrada por el usuario." & vbCrLf 'desplazamos el scroll Text1.SelStart = Len(Text1.Text) End Sub Private Sub Form_Load() Text1.Text = W.LocalIP 'Añadimos la ip al menu End Sub Private Sub Winsock1_Close() Winsock1.Close Text1.SelStart = Len(Text1.Text) Text1.Text = Text1.Text & "*** Conexion cerrada por el servidor***" & vbCrLf Text1.SelStart = Len(Text1.Text) End Sub Private Sub Winsock1_Connect() Text1.Text = Text1.Text & "*** Conexion establecida ***" & vbCrLf Text1.SelStart = Len(Text1.Text) End Sub Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Dim Buffer As String 'variable para guardar los datos 'obtenemos los datos y los guardamos en una variable Winsock1.GetData Buffer 'apuntamos al final del contenido del TextBox e 'insertamos los nuevos datos obtenidos Text1.SelStart = Len(Text1.Text) 'coloca el cursor al final del contenido Text1.Text = Text1.Text & "Servidor >" & Buffer 'mostramos los datos Text1.SelStart = Len(Text1.Text) 'coloca el cursor al final del contenido End Sub Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean) 'cerramos la conexion Winsock1.Close 'mostramos informacion sobre el error MsgBox "Error numero " & Number & ": " & Description, vbCritical End Sub
OJO, la imagen solo es para ejemplo ya que es obio que no es el servidor del control ciber.
![](http://i.imgur.com/9ElT4.jpg)
.................................................. ...........................................
servidor:
Código:
Imagen servidor:'Carga un nuevo socket al arreglo y devuelve su indice Private Function NuevoSocket() As Integer Dim numElementos As Integer 'numero de sockets Dim i As Integer 'contador 'obtiene la cantidad de Winsocks que tenemos numElementos = Winsock2.UBound 'recorre el arreglo de sockets For i = 0 To numElementos 'si algun socket ya creado esta inactivo 'utiliza este mismo para la nueva conexion If Winsock2(i).State = sckClosed Then NuevoSocket = i 'retorna el indice Exit Function 'abandona la funcion End If Next 'si no encuentra sockets inactivos 'crea uno nuevo y devuelve su identidad Load Winsock2(numElementos + 1) 'carga un nuevo socket al arreglo 'devuelve el nuevo indice NuevoSocket = Winsock2.UBound End Function Private Sub CommandXP1_Click() Dim numElementos As Integer 'numero de sockets Dim i As Integer 'contador 'obtiene la cantidad de Winsocks que tenemos numElementos = Winsock2.UBound 'recorre el arreglo de sockets For i = 0 To numElementos 'si el socket se encuentra conectado... If Winsock2(i).State = sckConnected Then 'enviamos el contenido de Text2 Winsock2(i).SendData Text2.Text & vbCrLf 'apuntamos al final del contenido del TextBox e 'insertamos los nuevos datos obtenidos Text1.SelStart = Len(Text1.Text) 'coloca el cursor al final del contenido Text1.Text = Text1.Text & "Sock" & i & ":Servidor >" & Text2.Text & vbCrLf 'mostramos los datos Text1.SelStart = Len(Text1.Text) 'coloca el cursor al final del contenido End If Next 'borramos Text2 Text2.Text = "" End Sub Private Sub CommandXP2_Click() 'cierra la conexion WinsockP.Close 'desplegamos un mensaje en la ventana Text1.SelStart = Len(Text1.Text) Text1.Text = Text1.Text & "*** Conexion cerrada por el usuario ***" & vbCrLf Text1.SelStart = Len(Text1.Text) End Sub Private Sub CommandXP3_Click() 'cerramos cualquier conexion previa WinsockP.Close 'asignamos el puerto local que abriremos WinsockP.LocalPort = Text3.Text 'deja el socket esuchando conexiones WinsockP.Listen 'desplegamos un mensaje en la ventana Text1.SelStart = Len(Text1.Text) Text1.Text = Text1.Text & "*** Escuchando conexiones ***" & vbCrLf Text1.SelStart = Len(Text1.Text) End Sub Private Sub CommandXP9_Click() Text1.Text = "" End Sub Private Sub Form_Load() Text1.Text = W.LocalIP 'Añadimos la ip al menu End Sub Private Sub WinsockP_Close() 'cierra la conexion WinsockP.Close 'desplegamos un mensaje en la ventana Text1.SelStart = Len(Text1.Text) Text1.Text = Text1.Text & "*** Conexion cerrada por el Cliente." & vbCrLf Text1.SelStart = Len(Text1.Text) End Sub Private Sub WinsockP_ConnectionRequest(ByVal requestID As Long) Dim numSocket As Integer 'el numero del socket 'mostramos un mensaje en la ventana Text1.SelStart = Len(Text1.Text) Text1.Text = Text1.Text & "*** Peticion numero " & requestID & vbCrLf Text1.SelStart = Len(Text1.Text) 'creamos un nuevo socket numSocket = NuevoSocket 'aceptamos la conexion con el nuevo socket Winsock2(numSocket).Accept requestID 'desplegamos un mensaje en la ventana Text1.SelStart = Len(Text1.Text) Text1.Text = Text1.Text & "Sock" & numSocket & ":*** Conexion aceptada, listo para interactuar ***" & vbCrLf Text1.SelStart = Len(Text1.Text) End Sub Private Sub WinsockP_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean) 'cerramos la conexion WinsockP.Close 'mostramos informacion sobre el error MsgBox "Error numero " & Number & ": " & Description, vbCritical End Sub Private Sub Winsock2_Close(Index As Integer) 'cierra la conexion Winsock2(Index).Close 'desplegamos un mensaje en la ventana Text1.SelStart = Len(Text1.Text) Text1.Text = Text1.Text & "Sock" & Index & ":*** Conexion cerrada por el Cliente." & vbCrLf Text1.SelStart = Len(Text1.Text) End Sub Private Sub Winsock2_DataArrival(Index As Integer, ByVal bytesTotal As Long) Dim Buffer As String 'variable para guardar los datos 'obtenemos los datos y los guardamos en una variable Winsock2(Index).GetData Buffer 'apuntamos al final del contenido del TextBox e 'insertamos los nuevos datos obtenidos Text1.SelStart = Len(Text1.Text) 'coloca el cursor al final del contenido Text1.Text = Text1.Text & "Sock" & Index & ":Cliente >" & Buffer 'mostramos los datos Text1.SelStart = Len(Text1.Text) 'coloca el cursor al final del contenido End Sub Private Sub Winsock2_Error(Index As Integer, ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean) 'cerramos la conexion Winsock2(Index).Close 'mostramos informacion sobre el error MsgBox "Error numero " & Number & ": " & Description, vbCritical End Sub
![](http://i.imgur.com/sb0Jg.jpg)
.................................................. .................................................. ....
Como puedo hacer para que el servidor atienda a cada cliente individualmente, es decir como mandarle mensajes a los clientes individual mentey como hacer o saber para que los clientes vayan siendo: 1,2,3,4,5,6,7,8,9,10 osea para que el servidor pueda dectectar.
si saben lo que es un control ciber sabrán de lo que hablo sin problemas, Gracias, no lo puedo hacer solo ayudenme
![Distraido](http://static.forosdelweb.com/fdwtheme/images/smilies/rolleyes.png)