Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 102,937 times

Contents

Related Categories

WinSock Control - Getting Prepared

Getting Prepared

To use the WinSock control on a network you need two things. A Server, and a Client. The Server will 'listen' to a specified port, and the client will attempt to connect to this port. Once a connection is made, data/text/files can be sent two and fro from both ends. 

First, you need to know the IP Address or Computer name of a PC. If you don't, then continue the tutorial, skipping the Ping part, and I will show you how.

It does not matter where you run the Server from, so long as you know this. To check your TCP/IP settings are correct, open a DOS prompt, and type Ping PC_Name, where PC_Name is the name of the PC, or the IP Address. You don't have to be at a different PC for this to work. You should get something like the below:

Pinging 192.168.0.2 with 32 bytes of data:

Reply from 192.168.0.2: bytes=32 time<10ms TTL=128
Reply from 192.168.0.2: bytes=32 time<10ms TTL=128
Reply from 192.168.0.2: bytes=32 time<10ms TTL=128
Reply from 192.168.0.2: bytes=32 time<10ms TTL=128

Ping statistics for 192.168.0.2:
Packets: Sent = 4, Received = 4, Lost = 0 (0% lo
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms

If you get this:

Pinging 192.169.0.2 with 32 bytes of data:

Destination host unreachable.
Destination host unreachable.
Destination host unreachable.
Destination host unreachable.

Ping statistics for 192.169.0.2:
Packets: Sent = 4, Received = 0, Lost = 4 (100%
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms

then your IP Address/PC Name is incorrect, or your TCP/IP protocol is not correctly configured. Refer to your Windows help for information on how to set it up.

To use the WinSock control, you do not actually need another PC to be on. You can run both the server and client on the same PC! Throughout this section, I will presume that this is the case, and therefore, we will have the server and client code in the same VB project.

To start, create a new project, and then add a reference to the WinSock control. To do this, click Project|Components..., and check the box next to the Microsoft WinSock Control.

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • Re: Re:

    Posted by zurna9 on 20 Feb 2008

    Make sure that you have a reference to the winsock ocx, and a winsock control in the project and verify that its called tcpClient (you can prob add a line like Dim tc...

  • Re:

    Posted by sandeep patil on 13 Feb 2008

    Hello, I was reading the "WinSock Control - Creating a Server" article
    I followed it exactly the way it was done on the page.

    I get the following error when testing my a...

  • Re: [78] WinSock Control

    Posted by sambariramesh on 15 Oct 2007

    akumar, you don't simply copy the EXE file on to other system. Use Package and Deployment wizard to make setup file so that it includes the winsock.ocx and other neccessary ...

  • Re: [78] WinSock Control

    Posted by akumar118 on 04 Aug 2007

    How to distribute MSwinsock.ocx along with the programm.
    The client and Server is working in my pc. But when I executed the exe file in another pc
    its giving me error.

    Can u please guide.

  • Re: [78] WinSock Control

    Posted by zurna9 on 16 May 2007

    you would either have to relay the message via the server -


    ie client sends message >>>>> server >>>> server forwards to other client


    or you would have ...