Results 1 to 5 of 5

Thread: Winsock Confusion

  1. #1

    Thread Starter
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Can anyone tell me what is wrong with this?? I got the exact code from microsoft. All i am trying to do is a simple chat, for my network at my house. thanks
    Form 1:

    Code:
    Private Sub Form_Load()
    With udpPeerA
        .RemoteHost = "PeerB"
        .RemotePort = 1001
        .Bind 1002
    End With
    frmPeerB.Show
    End Sub
    
    Private Sub txtSend_Change()
    udpPeerA.SendData txtSend.Text
    End Sub
    
    Private Sub udpPeerA_DataArrival _
    (ByVal bytesTotal As Long)
    Dim strData As String
    udpPeerA.GetData strData
    txtOutput.Text = strData
    End Sub
    Form 2:
    Code:
    Private Sub Form_Load()
    With udpPeerB
        .RemoteHost = "PeerA"
        .RemotePort = 1002
        .Bind 1001
    End With
    End Sub
    
    Private Sub Text1_Change()
    udpPeerB.SendData txtSend.Text
    End Sub
    
    Private Sub udpPeerB_DataArrival _
    (ByVal bytesTotal As Long)
    Dim strData As String
    udpPeerB.GetData strData
    txtOutput.Text = strData
    End Sub
    thanks

  2. #2
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Hi! Lethal, I don't think it will work. Because you need to set either one to act as server (I.e Always listen toa particular port number.) Whereas, the other should act as client that will try to connect to the server.

    try to use Winsock1.Listen properties

  3. #3

    Thread Starter
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    thanks, i'll give it a try. I'm actually using UDDP style for the winsock, where I read that it acts as a Peer to Peer relationship, and the code was supposed to work, just by copying and pasting it in. Guess Not, thanks

  4. #4
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Hi! lethal, you're rite as for the UDP you no need to listen any port. As long as any client bind to the paricular port number with a specified Remotehost value. Then the communication will commence.

    In your case, it does not work is may be you forget to set the Winsock AxtiveX control protocol. As for the Winsock ActiveX control, the default protocol is TCP.

    Code:
    'Code on the server section
    Option Explicit
    
    Private Sub CmdAction_Click()
    wsServer.SendData txtSend
    End Sub
    
    Private Sub Form_Load()
    With wsServer
        '*******************************************
        'for Remote PC this value must be set to the
        'Server IP
        'In this case I use the 127.0.0.1 is because
        'both server & client is on the same machine
        '*******************************************
        .Protocol = 1 'sckUDPProtocol
        .RemoteHost = "127.0.0.1"
        .RemotePort = 2020
    End With
    Load frmClient
    frmClient.Show
    End Sub
    
    Private Sub wsServer_DataArrival(ByVal bytesTotal As Long)
    Dim strData As String
    wsServer.GetData strData, vbString
    txtReceived.Text = strData
    End Sub
    Code:
    'Code on Client section
    Option Explicit
    
    Private Sub CmdAction_Click()
    wsClient.SendData txtSend
    End Sub
    
    Private Sub Form_Load()
    With wsClient
        '*******************************************
        'for Remote PC this value must be set to the
        'Server IP
        'In this case I use the 127.0.0.1 is because
        'both server & client is on the same machine
        '*******************************************
        .Protocol = 1 'sckUDPProtocol
        .RemoteHost = "127.0.0.1"
        .Bind 2020
    End With
    End Sub
    
    Private Sub wsClient_DataArrival(ByVal bytesTotal As Long)
    Dim strData As String
    wsClient.GetData strData, vbString
    txtReceived = strData
    End Sub


  5. #5
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Question

    In my sample code, I found something weird...
    When I set the wsClient or wsServer protocol to sckUDPProtocol that is:

    Code:
    wsServer.Protocol = sckUDPProtocol
    I encounter the following error:

    Expected variable or procedure, not project

    but if I change it to
    Code:
    wsServer.Protocol = 1
    Then everything is fine & running smooth. Do you've any idea abt this?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width