Results 1 to 8 of 8

Thread: Internet Winsock TXT messages

  1. #1

    Thread Starter
    Member Cahlel's Avatar
    Join Date
    Aug 2000
    Location
    Earth (I think)
    Posts
    63

    Question

    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
    Wisdom is supreme, therefore get wisdom,
    though it costs all you have, get understanding.
    Proverbs 4:7

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    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
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3

    Thread Starter
    Member Cahlel's Avatar
    Join Date
    Aug 2000
    Location
    Earth (I think)
    Posts
    63

    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.
    Wisdom is supreme, therefore get wisdom,
    though it costs all you have, get understanding.
    Proverbs 4:7

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Are you getting an error? Or is it just not sending text? Please explain what is happening and what you are doing.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    What val;ue are you putting in for txtAddress?
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  6. #6

    Thread Starter
    Member Cahlel's Avatar
    Join Date
    Aug 2000
    Location
    Earth (I think)
    Posts
    63
    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
    Wisdom is supreme, therefore get wisdom,
    though it costs all you have, get understanding.
    Proverbs 4:7

  7. #7
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    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
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  8. #8
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Try taking out the parameters after Connect

    Winsock1.Connect txtAddress.Text, 1000


    just use Winsock1.Connect

    then try again.

    Maybe ?!?!
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

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