VI spiego meglio (SCHEMATIZZANDO) quello che fa il programma:
codice sul SERVER (mio PC):
codice:
Option Explicit
Private Sub Form_Load()
stringaGET = ""
txtSTATE.Caption = "0 client Connected"
Winsock.Close
Winsock.Listen
End Sub
Private Sub Winsock_ConnectionRequest(ByVal RequestID As Long)
'ACCETTO UNA RICHIESTA DI CONNESSIONE SULLA PORTA 10101
If Winsock.State <> sckClosed Then
Winsock.Close
Winsock.LocalPort = 10101
Winsock.Listen
end if
Winsock.Accept RequestID
txtSTATE.Caption = "1 client Connected"
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''
'NON SO SE QUESTA SUB DEVE STARE ANCHE SUL SERVER????
Private Sub Winsock_Connect()
'DICHIARO LA STRINGA CHE IL SERVER INVIA AL CLIENT
'QUESTA SUB NON MI INVIA NULLA (al client)!!!!!!!!
Dim stringaSEND As String
stringaSEND = "Ciao Client_1"
Winsock.SendData stringaSEND
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Winsock_DataArrival(ByVal BytesTotal As Long)
'RECUPERO E VISUALIZZO LA STRINGA CHE MI HA INVIATO IL CLIENT
Dim stringaGET as String
Winsock.GetData stringaGET
txtCLIENT_NAME.Caption = stringaGET
End Sub
Private Sub Winsock_Close()
'CHIUDO LA CONNESSIONE
Winsock.Close
txtSTATE.Caption = "0 client Connected"
txtCLIENT_NAME.Caption = ""
End Sub
Questo invece è il codice del CLIENT (sempre stesso PC del server)
codice:
Option Explicit
Private Sub Form_Load()
TxtIP.Text = "127.0.0.1" '<--loopback address
txtPORT.Caption = "10101" '<--default port
txtSTATE.Caption = "Disconnected"
End Sub
Private Sub cmdConnect_Click()
'MI CONNETTO AL SERVER
Winsock.RemoteHost = TxtIP.Text
Winsock.RemotePort = 10101
txtPORT.Caption = Winsock.RemotePort
If Winsock.State <> sckClosed Then Winsock.Close
Winsock.Connect
End Sub
Private Sub Winsock_Connect()
'SE MI CONNETTO INVIO UNA STRINGA AL SERVER
'CON IL NOME DEL MIO CLIENT
txtSTATE.Caption = "Connected to SERVER"
Dim stringaSEND As String
stringaSEND = "Client_1"
Winsock.SendData stringaSEND
End Sub
Private Sub Winsock_DataArrival(ByVal BytesTotal As Long)
'RICEVO LA STRINGA DI SALUTO CHE MI HA INVIATO IL SERVER
'!!!!MA A ME, NON ARRIVA NESSUNA STRINGA!!!!!
Dim stringaGET As String
Winsock.GetData stringaGET
TxtMESSAGGIO_DAL_SERVER.Text = stringaGET
End Sub
Private Sub CmdDisconnect_Click()
Winsock.Close
txtSTATE.Caption = "Disconnected"
End Sub
Private Sub Winsock_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)
Winsock.Close
txtSTATE.Caption = "Error: " & Description
End Sub
ALLORA:
La stringa che io CLIENT invio al SERVER (sempre sul mio PC)
ARRIVA e viene visualizzata sulla textBox del SERVER...
INVECE...la stringa (di saluto) che il SERVER dovrebbe mandare a
me CLIENT, non arriva e non viene quindi visualizzata nella
textBox del CLIENT
WHY!!!!
P.S. quando avete un pò di tempo provate il codice e fatemi sapere
Grazie e