NAO CONSIGO FAZER MULTICONEXOES COM WINSOCK

USUARIO.EXCLUIDOS 05/03/2005 23:12:45
#71335
E o seguite eu to fazendo um chat simples pra multiplas conexoes mas eu ja tentei o seguinte codigo e nada de funcionar!

Alguem me ajude!

Codigo

Servidor:

 Private Sub Form_Load()
Label1.Caption = "Nome do computador: " & wss(0).LocalHostName & " IP: " & wss(0).LocalIP
wss(0).LocalPort = 100
wss(0).Listen
Caption = "Servidor: " & wss(0).LocalHostName
End Sub

Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
wss(0).SendData Text1.Text
Text1.Text = ""
End If
End Sub

Private Sub wss_ConnectionRequest(Index As Integer, ByVal requestID As Long)
On Error GoTo vai

If wss(0).State <> sckClosed Then wss(0).Close
wss(0).Accept requestID

Exit Sub

vai:
If Index = 0 Then
CnnSvr = CnnSvr + 1
Load wss(CnnSvr)
wss(CnnSvr).Accept requestID
End If
End Sub

Private Sub wss_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim strdados As String
wss(0).GetData strdados
enviar (strdados)
End Sub

Sub enviar(mensagem As String)
Text2.Text = Text2.Text & mensagem & vbNewLine
End Sub


Cliente:
Private Sub Command1_Click()
ws2(0).RemoteHost = Text3.Text
ws2(0).Connect
End Sub

Private Sub Form_Load()
ws2(0).RemotePort = 100
Caption = "Cliente"
End Sub

Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
ws2(0).SendData Text1.Text
Text1.Text = ""
End If
End Sub

Private Sub ws2_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim strdados As String
ws2(0).GetData strdados
enviar (strdados)
End Sub

Sub enviar(mensagem As String)
Text2.Text = Text2.Text & mensagem & vbNewLine
End Sub
USUARIO.EXCLUIDOS 05/03/2005 23:49:34
#71342
Resposta escolhida
Dim sock(0 To 20) As Boolean 'Conexoes ativas
Private Sub Wserver_ConnectionRequest(Index As Integer, ByVal requestID As Long)
For X = 1 To LIMITE_CONEXAO
If sock(X) = False Then
Load W2(X)
sock(X) = True
W2(X).Close
W2(X).Accept requestID
With ListConectados.ListItems.Add(X, "a" & X, requestID)
.SubItems(1) = W2(X).RemoteHost
.SubItems(2) = W2.Item(X).RemoteHostIP
.SubItems(3) = Time
End With

Exit For
End If
Next
Wserver(0).Close
Wserver(0).Listen
END SUB

adicione dois controles winsock
um com o Nome Wserver e o outro como W2
USUARIO.EXCLUIDOS 06/03/2005 18:57:14
#71446
Valeu cara Brigaduuuuuuuu!
Tópico encerrado , respostas não são mais permitidas