Results 1 to 12 of 12

Thread: Connect to ip?

  1. #1

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Connect to ip?

    You will need to use the
    vb Code:
    1. Winsock1.SendData
    method.

  2. #2
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Connect to ip?

    Quote Originally Posted by AxeFestis
    Tanks It work but now i want to send data over the connection please give me an example. I have read some but i dident mange them to work. And when i connect it just says 127.0.0.1 and that aren't my local ip.
    There are articles & tutorials all over the net explaining how to use the Winsock control.

    To send data you'd put:

    Code:
    Winsock1.SendData "Data here"
    Make sure the Winsock is connected or you will get an "invalid state" error. You could even do a simple check with an If statement:

    Code:
    If Winsock1.State = sckConnected Then Winsock1.SendData "Data here"
    If 127.0.0.1 is showing up as your local IP then that means you either put "127.0.0.1" or "localhost" as the RemoteHost in the Connect statement.

    To connect to yourself you can just use:

    Code:
    Winsock1.Connect Winsock1.LocalIP, 1234

  3. #3
    Junior Member
    Join Date
    Mar 2007
    Posts
    24

    Connect to ip?

    How do i connect to an ip whit winsock? Or something like that in 2005?


    Sorry if this i a n00b question
    Last edited by AxeFestis; Jul 6th, 2007 at 03:18 AM.

  4. #4
    Junior Member
    Join Date
    Mar 2007
    Posts
    24

    Re: Connect to ip?

    And can i show on the server if there are any connected?

  5. #5
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Connect to ip?

    To connect to an IP (using TCP) use this code:

    Code:
    Winsock1.Close
    Winsock1.Connect "123.123.123.123", 1234
    Where "123.123.123.123" is the IP address and 1234 is the port number.

    That will be in your client project.


    On the server project, you'd have a Winsock control and the code would be something like this:

    Code:
    Private Sub Form_Load()
        Winsock1.Close
        Winsock1.LocalPort = 1234
        Winsock1.Listen
    End Sub
    
    Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
        Winsock1.Close
        Winsock1.Accept requestID
        
        Me.Caption = "Connected [" & Winsock1.RemoteHostIP & "]"
    End Sub
    That's just for accepting one connection at a time. For multiple connections, you'd have to use a control array of Winsocks on the server side.

  6. #6
    Junior Member
    Join Date
    Mar 2007
    Posts
    24

    Re: Connect to ip?

    Tanks It work but now i want to send data over the connection please give me an example. I have read some but i dident mange them to work. And when i connect it just says 127.0.0.1 and that aren't my local ip.

  7. #7
    Junior Member
    Join Date
    Mar 2007
    Posts
    24

    Re: Connect to ip?

    OK, and how do you receive the data i tired get data but when i try to transfer it to a label or something it wont work could you give an example

  8. #8
    Junior Member
    Join Date
    Mar 2007
    Posts
    24

    Re: Connect to ip?

    Could somebody give a hole server client sample whit winsock, Thanks

  9. #9
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Connect to ip?

    Quote Originally Posted by AxeFestis
    Could somebody give a hole server client sample whit winsock, Thanks
    No. There are plenty of tutorials and example code on the net that you can learn from.

    Sometimes you just have to do SOMETHING yourself.

  10. #10
    Junior Member
    Join Date
    Mar 2007
    Posts
    24

    Re: Connect to ip?

    Sorry for ASKING in the forum then

  11. #11
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Connect to ip?

    I wasn't trying to sound rude, it's just there's so many people here expecting all the code to be given to them. I don't think that's what you were wanting.

    I can write a very basic client/server example if you like but really, there are so many examples on the internet.

    Take a look at these:
    http://www.pscode.com/vb/scripts/Bro...t=Alphabetical

  12. #12
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Connect to ip?

    Quote Originally Posted by AxeFestis
    Could somebody give a hole server client sample whit winsock, Thanks
    To send files:
    http://www.vbforums.com/showthread.php?t=377648

    Chat program:
    http://www.vbforums.com/showpost.php...2&postcount=43

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