help with visual basic 6

Discussion in 'Software' started by ale87, Nov 14, 2004.

  1. ale87

    ale87 Private E-2

    hey y'all i need some aid with visual basic's winsock control..because my head is about to crash.

    ok i want to do a prog conformed of two parts..client and server (dont worry is not a trojan)

    so the client has to send strings to the server(just like a chat system) and the server just displays the text.

    here is the code

    for the client
    --------------------------------------------------------------------------

    Dim IPadd
    Dim PORT As Integer

    Private Sub cmdConnect_Click()
    a = 0
    IPadd = txtip.Text
    PORT = Val(txtport.Text)
    'disconnect in case of already connected
    Winsock1.Close

    'nice part
    If IPadd = "" Then
    a = a + 1
    End If
    If txtport.Text = "" Then
    a = a + 1
    End If
    If a = 2 Then
    MsgBox "No ip and port to connect to"
    End If
    If a = 1 Then
    MsgBox "ip or port missing"
    'end of nice part

    Else
    lblStatus.Caption = "Trying " & IPadd & " on port " & PORT
    Winsock1.Connect IPadd, PORT
    End If
    End Sub

    Private Sub cmdExit_Click()
    End
    End Sub

    Private Sub cmdSend_Click()
    Dim texttosend As String
    texttosend = txtdata.Text
    lblStatus.Caption = "sending text..."
    Winsock1.SendData texttosend
    End Sub

    Private Sub Winsock1_Connect()
    'when connected change the offline status of winsock to sckconnected
    lblStatus.Caption = "Connection Succesful!"
    End Sub

    Private Sub Winsock1_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)
    lblStatus.Caption = "Error: " & Description
    End Sub

    end of client
    --------------------------------------------------------------------------

    code of server.
    --------------------------------------------------------------------------

    Private Sub cmdListen_Click()
    Dim inputport As Integer
    inputport = InputBox("Port to listen for connections", "port selection")
    If inputport <= 0 Or inputport >= 10000 Then
    MsgBox "Invalid port selection"
    Else
    Winsock1.LocalPort = inputport
    Winsock1.Listen
    lblStatus.Caption = "Listening on port " & inputport
    End If
    End Sub

    Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)

    MsgBox (requestID)
    lblStatus.Caption = "Connection Established!"

    End Sub

    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Dim data_rec As String
    Winsock1.GetData data_rec
    lblData.Caption = data_rec
    lblStatus.Caption = "Data received!"
    End Sub

    Private Sub Winsock1_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)
    lblStatus.Caption = "Error: " & Description
    End Sub

    end of server.
    --------------------------------------------------------------------------

    i get an error saying wrong protocol when i try to send strings....thanks in advanced...
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds