
21/10/2006, 12:40
|
 | | | Fecha de Ingreso: junio-2006
Mensajes: 89
Antigüedad: 18 años, 9 meses Puntos: 1 | |
Hola, acabo de resolver este problema, pero falta por pulir, aca el código Primer proyecto cliente, 1 form, 1 Socket, 2 textbox y 2 commandbutton.
Form1 = frmcliente
WinSocket = ws_cliente
Text1 = txtip
Text2 = txtconectar
Command1 = cmdconectar
Command2 = cmdenviar Código CLIENTE:
Código:
Private Sub cmdconectar_Click()
'winsock debe estar cerrado
Me.ws_cliente.Close
'Me.ws_cliente.Connect "192.168.0.102", "8888" 'Podemos dejar por defecto la IP
'Conectarse a la ip a través de una caja de texto
Me.ws_cliente.Connect Me.txtip, "8888"
End Sub
Código:
Private Sub cmdenviar_Click()
Me.ws_cliente.SendData Me.txtenviar.Text
End Sub
Código:
Private Sub Form_Load()
'Controles deshabilitados
cmdconectar.Enabled = False
cmdenviar.Enabled = False
End Sub
Código:
Private Sub Form_Unload(Cancel As Integer)
Me.ws_cliente.Close
End Sub
Código:
Private Sub txtenviar_Change()
If txtenviar.Text <> "" Then
cmdenviar.Enabled = True
Else
cmdenviar.Enabled = False
End If
End Sub
Código:
Private Sub txtip_Change()
If txtip.Text <> "" Then
cmdconectar.Enabled = True
Else
cmdconectar.Enabled = False
End If
End Sub
Segundo proyecto servidor, 1 form, 1 socket y 1 textbox
Form1 = frmcliente
WinSocket = ws_server
Text1 = txtrecibe Código SERVIDOR:
Código:
Private Sub Form_Load()
Me.ws_server.Close
Me.ws_server.LocalPort = "8888"
Me.ws_server.Listen
End Sub
Código:
Private Sub ws_server_ConnectionRequest(ByVal requestID As Long)
Me.ws_server.Close
Me.ws_server.Accept requestID
End Sub
Código:
Private Sub ws_server_DataArrival(ByVal bytesTotal As Long)
Dim texto_recibido As String
Me.ws_server.GetData texto_recibido
Me.txtrecibe = texto_recibido
'MsgBox "Advertencia: " & texto_recibido & "", vbCritical, "Mensaje de alerta" '<--- recibir el mensaje a través de un msgbox
End Sub
NOTA: El único problema es que si cierro el Form cliente y quiero enviar de nuevo otro mensaje no lo envia, porque hay que cerrar el form servidor y abrirlo nuevamente, hay que analizar eso, SALUDOS |