You are currently offline, waiting for your internet to reconnect

How To Use NT Simple TCP/IP Services for Winsock Testing

This article was previously published under Q177699
SUMMARY
Windows NT has a Simple TCP/IP Services service that can be used to testapplications that use the Winsock API and/or the Winsock Control. Ratherthan having to create both a client and server in Visual Basic, you cantest the client against this service.

A list of well-known ports available through this service can be found onan NT machine in the text document C:\WINNT\SYSTEM32\DRIVERS\ETC\SERVICES.
MORE INFORMATION
The following sample describes how to use the Microsoft Winsock Controlthat shipped with Visual Basic to call the Echo service and the QuoteService.

Verify that Simple TCP/IP Services is Running

Check to see if you can contact the server you are trying to attach to byrunning Ping <servername> at the command prompt. If the server responds, goto the control panel on the server and start the Services icon. Check thelist that comes up for Simple TCP/IP Services.

The Simple TCP/IP Services service must be running for these samples towork correctly. If Simple TCP/IP Services is not listed, double-clickNetwork in the Control Panel.

In Windows NT 3.51, click Add Software, choose TCP/IP Protocol and relatedcomponents, and click OK. In the dialog box that appears, click SimpleTCP/IP Services and click OK.

In Windows NT 4.0, click Add, choose Simple TCP/IP Services, and click OK.

The install program may ask you to provide the path to the Windows NTinstallation CD-ROM and will require that you restart the computer when itis finished.

Using the Echo Service

  1. Create a new Standard EXE project in Visual Basic.
  2. From the Projects menu, choose Components. Make sure that Microsoft Winsock Control is checked and click OK.
  3. Add a Winsock Control to the form and leave it named Winsock1.
  4. Add three CommandButtons named cmdConnect, cmdEcho, and cmdDisconnect, and then change the captions to Connect, Echo and Disconnect, respectively.
  5. Add two text boxes and leave them named Text1 and Text2, but change the MultiLine property on each to True.
  6. Add the following code to the form:
          Option Explicit      Const EchoPort = 7      Private Sub cmdConnect_Click()         Dim temp As String         temp = InputBox$("Enter a server name...", _                "Connect to the Echo Service", Winsock1.RemoteHost)         If temp <> "" Then         If Winsock1.State <> sckClosed Then Winsock1.Close            Winsock1.RemoteHost = temp            Winsock1.RemotePort = EchoPort            Winsock1.LocalPort = 0            Winsock1.Connect         End If      End Sub      Private Sub cmdDisconnect_Click()         If Winsock1.State <> sckClosed Then Winsock1.Close         cmdConnect.Enabled = True         cmdDisconnect.Enabled = False         cmdConnect.SetFocus      End Sub      Private Sub cmdEcho_Click()         Winsock1.SendData Text1.Text         cmdEcho.Enabled = False      End Sub      Private Sub Winsock1_Close()         If Winsock1.State <> 0 Then Winsock1.Close      End Sub      Private Sub Winsock1_Connect()         cmdConnect.Enabled = False         cmdEcho.Enabled = True         cmdDisconnect.Enabled = True      End Sub      Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)         Dim temp As String         temp = String(bytesTotal, "*")         Winsock1.GetData temp, vbString, bytesTotal         Text2.Text = temp         cmdEcho.Enabled = True      End Sub      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 "Error: " & Number & vbTab & Description, vbOKOnly, _                "Winsock Control 1 Error"         CancelDisplay = True      End Sub					

Using the Quote and Time Services

  1. Create a new STANDARD EXE project in Visual Basic.
  2. From the Projects menu, choose Components. Make sure that Microsoft Winsock Control is checked and then click OK.
  3. Add a Winsock Control to the form and leave it named Winsock1.
  4. Add two CommandButtons named cmdQuote and cmdTime, then change the captions to Quote and Time, respectively.
  5. Add a text box and leave it named Text1, but change the MultiLine property on it to True.
  6. Add the following code to the form:
          Const TimePort = 13, QuotePort = 17      Private Sub cmdQuote_Click()         Dim temp As String         temp = InputBox$("Enter a server name...", _                          "Get a Quote", Winsock1.RemoteHost)         If temp <> "" Then            If Winsock1.State <> sckClosed Then Winsock1.Close            Winsock1.RemoteHost = temp            Winsock1.RemotePort = QuotePort            Winsock1.LocalPort = 0            Winsock1.Connect         End If      End Sub      Private Sub cmdTime_Click()         Dim temp As String         temp = InputBox$("Enter a server name...", _                          "Get the time", Winsock1.RemoteHost)         If temp <> "" Then            If Winsock1.State <> sckClosed Then Winsock1.Close            Winsock1.RemoteHost = temp            Winsock1.RemotePort = TimePort            Winsock1.LocalPort = 0            Winsock1.Connect         End If      End Sub      Private Sub Winsock1_Close()         If Winsock1.State <> 0 Then Winsock1.Close      End Sub      Private Sub Winsock1_Connect()         Beep      End Sub      Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)         Dim temp As String         temp = String(bytesTotal, " ")         Winsock1.GetData temp, vbString, bytesTotal         Text1.Text = temp      End Sub      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 "Error: " & Number & vbTab & Description, _                vbOKOnly, "Winsock Control 2 Error"         CancelDisplay = True      End Sub					
Properties

Article ID: 177699 - Last Review: 07/11/2005 19:59:00 - Revision: 1.2

  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
  • Microsoft Visual Basic 6.0 Enterprise Edition
  • Microsoft Windows NT Server 3.51
  • Microsoft Windows NT Server 4.0 Standard Edition
  • Microsoft Windows NT Workstation 3.51
  • Microsoft Windows NT Workstation 4.0 Developer Edition
  • Microsoft Platform Software Development Kit-January 2000 Edition
  • kbhowto kbwinsock kbapi kbnetwork KB177699
Feedback