Results 1 to 10 of 10

Thread: Winsock Programming

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    23

    Winsock Programming

    I am an absolute beginner at network programming so please forgive any stupid questions. I am trying to build a simple application that sends a string out over a Winsock connection. I have a couple questions about Winsock programming.

    1. How do I make the winsock object available in my code. I have a sample project from a friend at work where the Winsock1 object is available, but I can't seem to get that same functionality in any new project. I looked for references etc but found none. Is there an import or something like that that I have to do?

    2. I want to set up a small test environmant for the Winsock app at home. What is required to make a Windows 2003 server responded to Winsock connection requests. All I need is for it to verify that I can establish the Winsock connection, I'll deal with what it does later.

    Any and all help would be greatley appreciated.

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    23

    Re: Winsock Programming

    I forgot to mention that I am doing all this in VB6, not my choice but that is what I have to do.

    Thanks,

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    23

    Re: Winsock Programming

    I found the answer to my first question but would still like info on how to make my server respond to Winsock connection requests. I haven't been able to make that work, even in code that I now works on the Internet(not my code, something I'm using to learn from)

  4. #4
    Lively Member
    Join Date
    Feb 2007
    Posts
    65

    Re: Winsock Programming

    You Mean That It Accepts The Connection, When Someone Connects ?

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    23

    Re: Winsock Programming

    Yes, I have a piece of code that looks like this:

    Private Sub Command1_Click()
    Winsock1.RemoteHost = "192.168.0.3"
    Winsock1.RemotePort = 30521
    Winsock1.Connect
    End Sub

    I just want to be able to get a "connected" status from Winsock. I have my Windows 2003 server at that address and I would like it to accept connections to this request from my XP system running this code.

  6. #6
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Winsock Programming

    The Winsock_Connect event fires when your connection attempt is successful, so thats how you can get the status if it worked, also the State property contains the current State of the Winsock, e.g. sckConnected, sckClosed etc.

    Search for some Winsock tutorials, what your trying to do is really simple. Just have an app listening on the server, and use the code you have to connect.

    Don't forget to make use of the Close and Error events of the Winsock control.
    Chris

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    23

    Re: Winsock Programming

    I agree is looks simple but it sure seems difficult to make it actually happen. When I execute the code in my previous reply, it just sits there and never gets connected. I didn't include the loop that I use, but I built a timer and then check for winsock1.state = sckConnected every second. It never happens.

  8. #8
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Winsock Programming

    Can you post the code that your using for the server program? Or are you trying to connect to an existing program thats running on the server? e.g. pop server.

    in your WS close event have
    winsock.close
    msgbox "closed by remote side"

    in WS error event:
    winsock.close
    msgbox Description

    This will help you debug the app. If it fails to connect, the Error event is fired, and you will get a msgbox saying "connection rejected"
    Chris

  9. #9
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Winsock Programming

    riversr, you need a program listening on port 30521 running on your server. It can be an IIS server or just another VB6 program with a Winsock control.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  10. #10
    Lively Member Nerd-Man's Avatar
    Join Date
    Dec 2006
    Location
    India
    Posts
    119

    Re: Winsock Programming

    using winsocks depends on what type of program you want to make. you can connect by the code below:

    VB Code:
    1. Winsock1.RemoteHost = "www.myserver.com", "80"
    2. Winsock1.Connect

    but if you want to do something else then you will have to use winsock1_connect to make any request. the above code will only connect to the server but to make sure you are connected or not, you will have to code in winsock1_connect

    VB Code:
    1. Private Sub Winsock1_Connect()
    2.  'if connected then
    3.  'MsgBox "I am connected."
    4. End Sub

    however i am new in socks and i am too trying to learn from this site.

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