Results 1 to 5 of 5

Thread: Winsock Question

  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.
    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()
    dudpPeerA.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
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177
    I don't use UDP so I may have missing something, but a couple of questions come to mind.

    Are you setting the protocol to UDP in your app?

    Are the machines named PeerA and PeerB (or is this just some sample code)?

    In addition, you have the line "dudpPeerA.SendData txtSend.Text" (note the 'd' at the beginning of the control name) in the txtSend_Change sub of Form1. Again, this may not be important if you didn't copy & paste code from your app.


  3. #3

    Thread Starter
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    thanks for the reply. Peer A and Peer B are the two forms names. I didn't copy and paste, so the typo was my fault. And yes, I did change properties on the form. All I'm doing is trying to make a simple chat. any suggestions??

  4. #4
    New Member
    Join Date
    Jul 2000
    Posts
    11

    Lightbulb

    Hi,

    First of all, which is your server? Do as follows

    sckServer is of course a winsock control
    sckClient is also of course a winsock control

    Server Side:
    Code:
    Private Sub Form_Load()
       sckServer.RemotePort = 1001
       sckServer.LocalPort = 1001
       sckServer.Listen
    End Sub
    
    Private Sub sckServer_ConnectionRequest(ByVal requestID As Long)
    sckServer.Accept requestID
    End Sub
    
    Private Sub sckServer_DataArrival(ByVal bytesTotal As Long)
       Dim strNewData As String
       sckServer.GetData strNewData
       ''Do whatever you want with the data here, i've used
       ''a message box for example
       MsgBox strNewdata
    End Sub
    Client Side:
    Code:
    Private Sub Form_Load()
       sckClient.RemotePort = 1001
       '' 127.0.0.1 is always your default local IP when online
       '' Or offline, it will need to be replaced with your 
       '' actual IP if you give it to someone else, note your
       '' IP changes every time you connect to your ISP
       sckClient.Connect "127.0.0.1", 1001
    End Sub
    
    Private Sub sckClient_DataArrival(ByVal bytesTotal As Long)
       Dim strNewData As String
       sckClient.GetData strNewData
       ''Do whatever you want with the data here, i've used
       ''a message box for example
       MsgBox strNewdata
    End Sub
    
    Private Sub cmdSend_Click()
       If sckClient.State = sckConnected Then
           sckClient.SendData "Hello World!!"
       Else
           MsgBox "You are not connected to a server!", vbCritical
       End If
    End Sub
    Hopefully that should help you out, just reply if it doesn't.

  5. #5

    Thread Starter
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    well, I used the UDPProtocol, which is a peer-to-peer relationship. I wasn't sure what else to use. Do u think your idea will be easier to implement for a small chat program? Also, on your code, I use to different forms right?? thansk

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