Click to See Complete Forum and Search --> : Winsock Confusion
Lethal
Dec 6th, 2000, 04:33 PM
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:
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:
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
Chris
Dec 7th, 2000, 10:05 AM
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
Lethal
Dec 7th, 2000, 02:45 PM
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
Chris
Dec 7th, 2000, 08:27 PM
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 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 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
Chris
Dec 7th, 2000, 08:31 PM
In my sample code, I found something weird...
When I set the wsClient or wsServer protocol to sckUDPProtocol that is:
wsServer.Protocol = sckUDPProtocol
I encounter the following error:
Expected variable or procedure, not project
but if I change it to
wsServer.Protocol = 1
Then everything is fine & running smooth. Do you've any idea abt this?
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.