Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Public Function GetWinSockState(WSCK As Winsock) As String
Select Case WSCK.State
Case sckClosed: GetWinSockState = "Chiuso"
Case sckClosing: GetWinSockState = "In Chiusura"
Case sckConnected: GetWinSockState = "Connesso"
Case sckConnecting: GetWinSockState = "Connettendo"
Case sckConnectionPending: GetWinSockState = "Connessione in attesa"
Case sckError: GetWinSockState = "Errore"
Case sckHostResolved: GetWinSockState = "Nome Host Risolto"
Case sckListening: GetWinSockState = "In Ascolto"
Case sckOpen: GetWinSockState = "Aperto"
Case sckResolvingHost: GetWinSockState = "Risolvendo Host"
End Select
End Function
Dim State As Status
Dim Version As String
Dim Ind As Integer
Dim Nick As String
Enum Status
Active = 1
Closed = 0
End Enum
Private Sub Connetti_Click()
Dim Temp As String
Dim arr() As String
If State = Closed Then
arr() = Split(InputBox("Inserire il Server e la Porta separati dai due punti (" & vbCrLf & "Server:Porta"), ":")
If UBound(arr()) = 1 Then
TCP.Connect arr(0), Val(arr(1))
Else
MsgBox "Dati non inseriti correttamente"
End If
Else
If MsgBox("Disconnettersi?", vbYesNo, "Disconnessione") = vbYes Then
TCP.Close
TCP_Close
End If
End If
End Sub
Private Sub mnuEsci_Click()
Unload Me
End Sub
Private Sub Form_Load()
Version = App.Major & "." & App.Minor & "." & App.Revision
SetState Closed
End Sub
Sub AddText(Testo As String, Optional ACapo As Boolean = True) ' Aggiunge testo alla
txtChat.Text = txtChat.Text & Testo ' chat
If ACapo Then txtChat.Text = txtChat.Text & vbCrLf
txtChat.SelStart = Len(txtChat.Text)
txtChat.Refresh
End Sub
Sub SetState(Stat As Status) ' Imposta lo stato del Client
Dim bOn As Boolean
bOn = (Stat = Active)
txtChat.Enabled = bOn
txtInvia.Enabled = bOn
InfoServ = bOn
lstUtenti.Enabled = bOn
If bOn Then
Connetti.Caption = "Disconnetti"
Else
Connetti.Caption = "Connetti"
lstUtenti.Clear
End If
'If Not bOn Then
State = Stat
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Cancel = (MsgBox("Uscire?", vbYesNo, "Uscita") = vbNo)
End Sub
Private Sub InfoServ_Click()
TCP.SendData InfoServer
End Sub
Private Sub lstUtenti_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim Nick As String
If Button = vbRightButton And lstUtenti.ListCount > 0 Then
Nick = lstUtenti.List(lstUtenti.ListIndex)
TCP.SendData InfoUser & Separatore & Nick
AddText "Richiesta Info su " & Nick & " inoltrata"
End If
End Sub
Private Sub Service_Timer()
lblStato.Caption = "Stato: " & GetWinSockState(TCP())
End Sub
Private Sub TCP_Close()
TCP.Close
AddText "Connessione Chiusa al Server"
SetState Closed
Me.Caption = "Client Chat"
End Sub
Sub Pulisci(ByRef Stringa As String)
Stringa = Replace(Trim$(Stringa), vbCrLf, vbNullString)
End Sub
Private Sub TCP_Connect()
Dim Descr As String
SetState Active ' Attiva i controlli
Do
Nick = InputBox("Inserisci il Nick, al massimo 10 caratteri", "Nick")
Call Pulisci(Nick)
If Len(Nick) = 0 Or Len(Nick) > 10 Then
If MsgBox("Chiudere la connessione?", vbYesNo) = vbYes Then
TCP_Close
Exit Sub
End If
Else
Exit Do
End If
Loop
Descr = InputBox("Inserisci una tua descrizione")
If Len(Descr) = 0 Then Descr = "Nessuna Descrizione"
AddText "Connesso a " & TCP.RemoteHostIP & " con successo"
TCP.SendData NuovoUtente & Separatore & Nick & Separatore & Descr & Separatore & Version & _
Separatore & Environ$("OS")
End Sub
Private Sub TCP_DataArrival(ByVal bytesTotal As Long)
Dim data As String
Dim arr() As String
Dim n As Integer
Dim UB As Integer
Dim arry() As String
TCP.GetData data
arr() = Split(data, Separatore)
Select Case arr(0)
Case ListaUs ' Lista degli utenti
arry() = Split(arr(1), "|")
UB = UBound(arry())
lstUtenti.Clear
For n = 0 To UB
lstUtenti.AddItem arry(n)
Next
Case Testo ' Testo da aggiungere alla chat
AddText arr(1)
Case InfoServer ' Risposta info server
MsgBox arr(1)
Case InfoUser ' Risposta info utente (WhoIs)
MsgBox arr(1)
Case NickEsistente ' In caso di nick già esistente
MsgBox "Nick rifiutato perchè già esistente, reinserire i dati", vbInformation
TCP_Connect
Case Autenticato ' Autenticazione al server completata
AddText "Autenticazione completata"
Me.Caption = "Client Chat -> " & Nick
Case DatiCorrotti ' Autenticazione sbagliata
AddText "Autenticazione sbagliata"
TCP_Connect
End Select
End Sub
Private Sub TCP_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)
TCP.Close
AddText "Si è verificato l'errore " & Number & ": " & Description & vbCrLf & "Connessione Persa"
TCP_Close
End Sub
Sub SendText(Text As String)
TCP.SendData Testo & Separatore & Text
End Sub
Private Sub txtInvia_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn And Len(txtInvia.Text) > 0 Then
TCP.SendData Testo & Separatore & txtInvia.Text
txtInvia.Text = vbNullString
End If
End Sub
Public Function GetWinSockState(WSCK As Winsock) As String
Select Case WSCK.State
Case sckClosed: GetWinSockState = "Chiuso"
Case sckClosing: GetWinSockState = "In Chiusura"
Case sckConnected: GetWinSockState = "Connesso"
Case sckConnecting: GetWinSockState = "Connettendo"
Case sckConnectionPending: GetWinSockState = "Connessione in attesa"
Case sckError: GetWinSockState = "Errore"
Case sckHostResolved: GetWinSockState = "Nome Host Risolto"
Case sckListening: GetWinSockState = "In Ascolto"
Case sckOpen: GetWinSockState = "Aperto"
Case sckResolvingHost: GetWinSockState = "Risolvendo Host"
End Select
End Function
Dim State As Status
Dim Version As String
Dim Ind As Integer
Dim Nick As String
Enum Status
Active = 1
Closed = 0
End Enum
Private Sub Connetti_Click()
Dim Temp As String
Dim arr() As String
If State = Closed Then
arr() = Split(InputBox("Inserire il Server e la Porta separati dai due punti (" & vbCrLf & "Server:Porta"), ":")
If UBound(arr()) = 1 Then
TCP.Connect arr(0), Val(arr(1))
Else
MsgBox "Dati non inseriti correttamente"
End If
Else
If MsgBox("Disconnettersi?", vbYesNo, "Disconnessione") = vbYes Then
TCP.Close
TCP_Close
End If
End If
End Sub
Private Sub mnuEsci_Click()
Unload Me
End Sub
Private Sub Form_Load()
Version = App.Major & "." & App.Minor & "." & App.Revision
SetState Closed
End Sub
Sub AddText(Testo As String, Optional ACapo As Boolean = True) ' Aggiunge testo alla
txtChat.Text = txtChat.Text & Testo ' chat
If ACapo Then txtChat.Text = txtChat.Text & vbCrLf
txtChat.SelStart = Len(txtChat.Text)
txtChat.Refresh
End Sub
Sub SetState(Stat As Status) ' Imposta lo stato del Client
Dim bOn As Boolean
bOn = (Stat = Active)
txtChat.Enabled = bOn
txtInvia.Enabled = bOn
InfoServ = bOn
lstUtenti.Enabled = bOn
If bOn Then
Connetti.Caption = "Disconnetti"
Else
Connetti.Caption = "Connetti"
lstUtenti.Clear
End If
'If Not bOn Then
State = Stat
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Cancel = (MsgBox("Uscire?", vbYesNo, "Uscita") = vbNo)
End Sub
Private Sub InfoServ_Click()
TCP.SendData InfoServer
End Sub
Private Sub lstUtenti_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim Nick As String
If Button = vbRightButton And lstUtenti.ListCount > 0 Then
Nick = lstUtenti.List(lstUtenti.ListIndex)
TCP.SendData InfoUser & Separatore & Nick
AddText "Richiesta Info su " & Nick & " inoltrata"
End If
End Sub
Private Sub Service_Timer()
lblStato.Caption = "Stato: " & GetWinSockState(TCP())
End Sub
Private Sub TCP_Close()
TCP.Close
AddText "Connessione Chiusa al Server"
SetState Closed
Me.Caption = "Client Chat"
End Sub
Sub Pulisci(ByRef Stringa As String)
Stringa = Replace(Trim$(Stringa), vbCrLf, vbNullString)
End Sub
Private Sub TCP_Connect()
Dim Descr As String
SetState Active ' Attiva i controlli
Do
Nick = InputBox("Inserisci il Nick, al massimo 10 caratteri", "Nick")
Call Pulisci(Nick)
If Len(Nick) = 0 Or Len(Nick) > 10 Then
If MsgBox("Chiudere la connessione?", vbYesNo) = vbYes Then
TCP_Close
Exit Sub
End If
Else
Exit Do
End If
Loop
Descr = InputBox("Inserisci una tua descrizione")
If Len(Descr) = 0 Then Descr = "Nessuna Descrizione"
AddText "Connesso a " & TCP.RemoteHostIP & " con successo"
TCP.SendData NuovoUtente & Separatore & Nick & Separatore & Descr & Separatore & Version & _
Separatore & Environ$("OS")
End Sub
Private Sub TCP_DataArrival(ByVal bytesTotal As Long)
Dim data As String
Dim arr() As String
Dim n As Integer
Dim UB As Integer
Dim arry() As String
TCP.GetData data
arr() = Split(data, Separatore)
Select Case arr(0)
Case ListaUs ' Lista degli utenti
arry() = Split(arr(1), "|")
UB = UBound(arry())
lstUtenti.Clear
For n = 0 To UB
lstUtenti.AddItem arry(n)
Next
Case Testo ' Testo da aggiungere alla chat
AddText arr(1)
Case InfoServer ' Risposta info server
MsgBox arr(1)
Case InfoUser ' Risposta info utente (WhoIs)
MsgBox arr(1)
Case NickEsistente ' In caso di nick già esistente
MsgBox "Nick rifiutato perchè già esistente, reinserire i dati", vbInformation
TCP_Connect
Case Autenticato ' Autenticazione al server completata
AddText "Autenticazione completata"
Me.Caption = "Client Chat -> " & Nick
Case DatiCorrotti ' Autenticazione sbagliata
AddText "Autenticazione sbagliata"
TCP_Connect
End Select
End Sub
Private Sub TCP_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)
TCP.Close
AddText "Si è verificato l'errore " & Number & ": " & Description & vbCrLf & "Connessione Persa"
TCP_Close
End Sub
Sub SendText(Text As String)
TCP.SendData Testo & Separatore & Text
End Sub
Private Sub txtInvia_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn And Len(txtInvia.Text) > 0 Then
TCP.SendData Testo & Separatore & txtInvia.Text
txtInvia.Text = vbNullString
End If
End Sub
dv è il problema?...
cmq mi da l'errore su questa porzione d codice:
-Public Function GetWinSockState(WSCK As Winsock)
mica devo kiamare il modulo e il form client in nomi specifici?...io nn credo.risp.