Results 1 to 6 of 6

Thread: Another Winsock Problem :)

  1. #1
    Guest

    Post

    Ok, Iming writeing a client/server thing. For some reason It only works on my computer. It a send someone else the server and try to connect over the internet it doesnt work.

    Here is the basic connection part of the program:

    CLIENT

    Private Sub Command1_Click()
    On Error GoTo error
    'Close old connections
    Winsock1.Close
    ' connect
    Winsock1.Connect Text1.Text, 5678
    Command1.Enabled = False 'disable connect command button
    Command2.Enabled = True 'enable diconect command button

    error:
    Exit Sub
    End Sub


    SERVER

    Private Sub Form_Load()
    MakeProgramStealth
    ' here it listen for connection to port 5678
    Winsock1.LocalPort = 5678
    Winsock1.Listen
    End Sub

    Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
    ' it's accept connection when anything asks
    If Winsock1.State <> sckClosed Then Winsock1.Close
    Winsock1.Accept requestID
    End Sub

    IF someone could find why this connects when both are on my computer and not over the internet I would greatly appreciate it.

    Thanks

  2. #2
    Addicted Member
    Join Date
    Jan 1999
    Posts
    173

    Post

    What are you typing into text1?

    ------------------
    "To the glory of God!"


  3. #3
    Guest

    Post

    You have to know the IP and Port of the listening server. Your port 5678 is probably ok, but are you certain about the IP ? Some IP's are dynamically assigned and therefore will vary each time you start your internet connection.
    I had my server publish the current IP and Port to a web page, then the client would get the info from that page and connect to the current IP and Port.
    Or you can try to connect to a range of IP's with the same port. Your app should be the only one that responds (if it really isn't being used) to a valid combination.

  4. #4
    Guest

    Post

    Text1.text is a ip address

  5. #5
    Guest

    Post

    Yes, but are you certain that it is a valid IP address NOW? Read the part about dynamically assigned again.

  6. #6
    Guest

    Post

    Make sure you aint useing your own ip or 127.0.0.1localhost.

    Also try checking(?) if there aren't any errors
    Code:
    Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
        MsgBox "Woepsie: " & Description, vbOKOnly + vbCritical, "Error!!!!!!!!"
    End Sub
    you could also check the state of the winsock.

    Code:
    Private Sub Command1_Click()
        On Error GoTo Error
        'Close old connections
        Winsock1.Close
        
        'Connect
        Winsock1.Connect Text1.Text, 5678
        
        'Wait for connection, but abort if there is an error
        Do Until Winsock1.State = sckConnected And Not Winsock1.State = sckError
            DoEvents
        Loop
        If Winsock1.State = sckError Then
            MsgBox "Error occurd while trying to connect to " & Text1
        End If
        
        Command1.Enabled = Not (Winsock1.State = sckConnected) 'disable connect command button
        Command2.Enabled = (Winsock1.State = sckConnected) 'enable disconnect command button
    Error:
        Exit Sub
    End Sub
    ------------------

    Vincent van den Braken
    EMail: [email protected]
    ICQ: 15440110
    Homepage: http://www.azzmodan.demon.nl




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