-
why won't this code work?
the sending App:
On Error Resume Next
Winsock1.RemoteHost = txtAddress.Text
Winsock1.RemotePort = 1000
Winsock1.Connect txtAddress.Text, 1000
Do Until Winsock1.State = sckConnected
DoEvents: DoEvents: DoEvents: DoEvents
If Winsock1.State = sckError Then
MsgBox "There was a fatal error!"
Exit Sub
End If
Loop
Winsock1.SendData (txtMessage.Text)
Winsock1.Close
then receiving app:
Private Sub Form_Load()
On Error Resume Next
Winsock1.LocalPort = 1000
Winsock1.Listen
End Sub
Private Sub Form_Unload(Cancel As Integer)
Form3.Hide
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
On Error Resume Next
If Winsock1.State <> sckClosed Then Winsock1.Close
Winsock1.Accept requestID
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
On Error Resume Next
Dim strIncoming As String
Winsock1.GetData strIncoming
textbox1.Text = textbox1.Text & vbCrLf & strIncoming
End Sub
-
Instead of using :
Do Until Winsock1.State = sckConnected
Why dont you just use the Connect() Event for the winsock control ?
Also, try this :
Code:
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
On Error Resume Next
Dim strIncoming As String
Winsock1.GetData strIncoming, vbString
'note the above vbString part
textbox1.Text = textbox1.Text & vbCrLf & strIncoming
End Sub
-
err
Because for some reason it won't connect, I get "Can't connect!" (my own error trapping that means there's an error connecting.
-
Are you getting an error? Or is it just not sending text? Please explain what is happening and what you are doing.
-
What val;ue are you putting in for txtAddress?
-
I am getting the error I put in there for error trapping (see code) and for the IP, i'm putting 127.0.0.1
-
The localhost address doesnt always work, well at least in my experience.
Make sure the Winsock controls are using TCP and not UDP.....
Also, run 'winipcfg', get the IP of your network adapter if you have one, and try using that....
Could you post the project zipped as an attachment ?
- jamie
-
Try taking out the parameters after Connect
Winsock1.Connect txtAddress.Text, 1000
just use Winsock1.Connect
then try again.
Maybe ?!?!