VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This is a Client chat program using Winsock, You can see the status of the remote server and send

by Lightning_Storm (4 Submissions)
Category: Internet/HTML
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Mon 11th December 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This is a Client chat program using Winsock, You can see the "status" of the remote server and send Messages.You can see your local IP too.All

API Declarations


'socket de comunicação windows, e protocolo tcp/ip
'qualquer duvida ou comentario [email protected].
'esse aplicativo e de uso publico podendo ser alterado da
'forma que for coveniente.
'desenvolvido em 11/11/2000 (dd/mm/yyyy)
Dim BytesEnviados As Long
Dim BytesRecebidos As Long

Rate This is a Client chat program using Winsock, You can see the status of the remote server and send



'Verifica se campo ip remoto foi preenchido
If txtIP.Text = "" Then
'Se não sai da sub rotina
    MsgBox ("Preencha o campo IP Remoto")
    txtIP.SetFocus
    Exit Sub
End If
'Veriica estado do socket, se ele estiver fechado prepara conecta-se
If WskCliente.State = sckClosed Then
    cmdConectar.Caption = "&Desconectar"
    'pega o ip do servidor
    WskCliente.RemoteHost = txtIP.Text
    'pega a porta do servidor
    WskCliente.RemotePort = CInt(txtPorta.Text)
    'aciona o evento de conecção
    WskCliente.Connect
    txtReceber.Enabled = True
    txtEnviar.Enabled = True
    'Exibe status na barra
    StatusBar1.Panels(1).Text = "Conectado"
    If WskCliente.State <> sckConnected Then
        StatusBar1.Panels(1).Text = "Não foi possivel Conectar"
    End If
Else
    'se não fecha comunicação
    cmdConectar.Caption = "&Conectar"
    WskCliente.Close
     txtReceber.Enabled = False
    txtEnviar.Enabled = False
    StatusBar1.SimpleText = "Desconectado"
    BytesEnviados = 0
    StatusBar1.Panels(3).Text = "BytesEnviados: 0"
    BytesRecebidos = BytesRecebidos + 1
    StatusBar1.Panels(2).Text = "Bytes Recebidos: 0 "
End If
End Sub



Private Sub cmdMensagem_Click()
Dim AcumulaCaracter As String
'Verifica se mantem comunicação aberta com servidor se sim envia dados
If WskCliente.State = sckConnected Then
    'envia para o servidor os dados digitados no campo
    WskCliente.SendData (txtEnviar.Text)
    BytesEnviados = BytesEnviados + 1
    AcumulaCaracter = ""
    'Armazena bytes enviados
    StatusBar1.Panels(3).Text = "Rx: " & BytesEnviados
    txtEnviar.Text = ""
Else
    'se comunicação for diferente de sckConnected
    txtEnviar.Enabled = False
    MsgBox ("Não há socket ouvindo!")
    cmdConectar.SetFocus
    'Fecha socket para evitar travamento
    WskCliente.Close
    If WskCliente.State = sckClosed Then
        cmdConectar.Caption = "&Conectar"
    End If
    Exit Sub
End If
End Sub

Private Sub Form_Load()
'Pega no load informação do ip da maquina local
txtIPLOcal.Text = WskCliente.LocalIP
StatusBar1.Panels(4).Text = "Hora Atual: " & Time
'dispara timer
tmrConectado.Enabled = True
End Sub

Private Sub mnuAbout_Click()
'exibe info sobre Lightning Storm
frmAbout.Show (1)
End Sub

Private Sub tmrConectado_Timer()
Dim AcumulaTempo As Long
'Insere a hora atual na statusbar
StatusBar1.Panels(4).Text = "Hora Atual: " & Time
'verifica condição
If WskCliente.State = sckClosed Or _
WskCliente.State = sckConnecting Then
    StatusBar1.Panels(1).Text = "Desconectado"
    cmdConectar.Caption = "Conectar"
End If
If WskCliente.State = sckConnected Then
    StatusBar1.Panels(1).Text = "Conectado"
End If
If WskCliente.State = sckClosing Then
    WskCliente.Close
    cmdConectar.Caption = "Conectar"
End If
End Sub


'Evento de recebimento de dados do sevidor
Private Sub WskCliente_DataArrival(ByVal bytesTotal As Long)
Dim strRecebe As String
'pega dados enviados pelo servidor
WskCliente.GetData strRecebe
'envia o dados recebidos para o campo de saida
txtReceber.Text = strRecebe
'Acumula bytes recebidos
BytesRecebidos = BytesRecebidos + 1
StatusBar1.Panels(2).Text = "Rx: " & BytesRecebidos
End Sub
*************************************************************************
frmAbout

Private Sub cmdOK_Click()
  Unload Me
End Sub

Download this snippet    Add to My Saved Code

This is a Client chat program using Winsock, You can see the status of the remote server and send Comments

No comments have been posted about This is a Client chat program using Winsock, You can see the status of the remote server and send. Why not be the first to post a comment about This is a Client chat program using Winsock, You can see the status of the remote server and send.

Post your comment

Subject:
Message:
0/1000 characters