Results 1 to 15 of 15

Thread: winsock help

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Posts
    262

    winsock help

    i put a winsock control on both client and server and named them just Winsock then on the server side i have this code that i got from a sample:

    VB Code:
    1. Private Sub Form_Load()
    2.  
    3. Winsock.LocalPort = 6000
    4. Winsock.Listen
    5.  
    6. End Sub
    7.  
    8. Private Sub Winsock_ConnectionRequest(ByVal requestID As Long)
    9. Winsock.Close connection
    10. Winsock.Accept requestID End Sub
    11.  
    12. Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)
    13.  
    14. Dim incommingData As String
    15. Winsock.GetData incommingData
    16.  
    17. txtLogin.Text = incommingData
    18. End Sub

    Then on the client side i have this from the other sample..:

    VB Code:
    1. Private Sub winsock_connect()
    2. MsgBox "We are connected"
    3. End Sub
    4.  
    5.  
    6. Public Sub cmdLogin_Click()
    7. Winsock.RemoteHost = "127.0.0.1"
    8. Winsock.RemotePort = 6000
    9. Winsock.Connect
    10. Winsock.SendData txtLogin.Text
    11. End Sub

    Now when I hit "login" i get the message telling me the connection was made but the data doesnt appear to be transferring... i have a text box called txtLogin and it just stays blank.. any ideas?
    Last edited by ooOOJaVaOOoo; Aug 10th, 2005 at 02:08 PM.

  2. #2
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    537

    Re: winsock help

    Your server is listening on a different port.

    VB Code:
    1. Server:
    2. Winsock.LocalPort = 6000
    3.  
    4. Client:
    5. Winsock.RemotePort = 15151

    If that's not the problem, i'm not sure what is...

    -Sir Loin

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Posts
    262

    Re: winsock help

    haha thats my bad i was trying different ports and didnt post them with the same ports.. thats doesnt fix it..

  4. #4
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Re: winsock help

    Try adding DoEvents after sending data because sometimes it takes time to send the data accross. Also might want to check to see if winsock is connected.

    VB Code:
    1. Public Sub cmdLogin_Click()
    2.     Winsock.RemoteHost = "127.0.0.1"
    3.     Winsock.RemotePort = 6000
    4.     Winsock.Connect
    5.    
    6.     While Winsock.State <> sckConnected
    7.         If Winsock.State = sckClosed Then GoTo Cnn_Lost
    8.         DoEvents
    9.     Wend
    10.     Winsock.SendData txtLogin.Text
    11.     DoEvents
    12.     Winsock.Close
    13. Cnn_Lost:
    14.      Winsock.Close
    15. End Sub

  5. #5
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    537

    Re: winsock help

    Check to see if both Winsock controls are using the same protocol.

    -Sir Loin

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Posts
    262

    Re: winsock help

    nothing seems to be working on this.. all i can do is get the connection.. no data is being sent that i can see.. my goal for this section is to send a username and password to the server and then have it check the login/pw to a database and then if all is ok go ahead and show the next form.. i already have the login/pw authentication work but not through the server side software, just the client connecting straight to the database..

  7. #7
    Fanatic Member
    Join Date
    Jan 2005
    Location
    In front of this pc.
    Posts
    580

    Re: winsock help

    Are you verifying the connection before sending the data? If not perhaps you're having a timing issue....

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Posts
    262

    Re: winsock help

    i have a message that pops up and notifies that the connection is created

  9. #9
    Fanatic Member
    Join Date
    Jan 2005
    Location
    In front of this pc.
    Posts
    580

    Re: winsock help

    This just ain't my day for getting my stuff straight the first time....lol

    Ok, maybe try adding a DoEvents between the connection and sending of data. With both winsocks running on the same pc you'll probably have to relenquish some CPU cycles.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Posts
    262

    Re: winsock help

    already tried

  11. #11
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: winsock help

    are you testing these both in the same program or two different programs.
    I'd suggest putting them into two different programs so there won't be any blocking issues.

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Posts
    262

    Re: winsock help

    two seperate programs.. is there anyway someone can post a sample of something that might be another way to do what i am trying to accomplish?

  13. #13
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: winsock help

    You can't send data until you're sure you've connected.
    try putting the connection request and datasend into two separate buttons, see if that helps

    Another way would be to put the sending in the connect event of the client.

  14. #14
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: winsock help

    Here is a working sample. Pino wrote it. 11 downloads so far.

    Winsock

  15. #15
    Hyperactive Member
    Join Date
    Apr 2004
    Location
    Philippines
    Posts
    285

    Re: winsock help

    try putting Winsock.senddata txtLogin.text under Winsock_connect event to make sure that the winsock control is already connected to the server before sending any data.

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