VERSION 5.00 Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX" Begin VB.Form frmDCMotorClient BackColor = &H0080FF80& Caption = "DC Motor Client" ClientHeight = 3705 ClientLeft = 60 ClientTop = 345 ClientWidth = 6150 LinkTopic = "Form1" ScaleHeight = 3705 ScaleWidth = 6150 StartUpPosition = 3 'Windows Default Begin VB.CommandButton cmdEnter Caption = "Enter" Height = 615 Left = 5160 TabIndex = 4 Top = 120 Width = 855 End Begin VB.TextBox txtRPM Height = 615 Left = 3000 TabIndex = 3 Text = "0" Top = 120 Width = 1815 End Begin VB.TextBox txtOutput Height = 2295 Left = 120 MultiLine = -1 'True ScrollBars = 2 'Vertical TabIndex = 0 Top = 1200 Width = 5895 End Begin MSWinsockLib.Winsock tcpClient Left = 4800 Top = 720 _ExtentX = 741 _ExtentY = 741 _Version = 393216 End Begin VB.Label lblRPM BackColor = &H0080FF80& Caption = "Please Enter the requested motor RPM and click Enter:" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 615 Left = 120 TabIndex = 2 Top = 120 Width = 2655 End Begin VB.Label lblTextOutput BackColor = &H0080FF80& Caption = "Status Textbox" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H00000000& Height = 255 Left = 240 TabIndex = 1 Top = 840 Width = 1575 End End Attribute VB_Name = "frmDCMotorClient" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False ' FILE: LEDClient ' DATE: 01/15/00 21:30 ' AUTH: P.Oh ' DESC: TCP Client. Users clicks on numbered buttons ' and server should respond which button was pressed ' REFS: Deitel p. 829 Fig. 19.12 Private Sub cmdEnter_Click() ' Send requested RPM to server Call tcpClient.SendData(txtRPM.Text) txtOutput.Text = txtOutput.Text & _ "Client entered" & txtRPM.Text & "RPM" & vbCrLf txtOutput.SelStart = Len(txtOutput.Text) End Sub Private Sub Form_Load() ' Set up local port and wait for connection tcpClient.RemoteHost = InputBox("Enter the remote host IP Address", _ "IP Address", "localhost") If tcpClient.RemoteHost = "" Then tcpClient.RemoteHost = "localhost" End If tcpClient.RemotePort = 5000 ' server port Call tcpClient.Connect ' connect to RemoteHost address End Sub Private Sub Form_Terminate() Call tcpClient.Close End End Sub Private Sub tcpClient_Close() Call tcpClient.Close ' server closed, client should too txtOutput.Text = txtOutput.Text & "Server closed connection." & vbCrLf txtOutput.SelStart = Len(txtOutput.Text) End Sub Private Sub tcpClient_Connect() ' When connection occurs, display a message txtOutput.Text = "Connected to IP address: " & _ tcpClient.RemoteHostIP & vbCrLf & "Port #: " & _ tcpClient.RemotePort & vbCrLf & vbCrLf End Sub Private Sub tcpClient_DataArrival(ByVal bytesTotal As Long) Dim message As String Call tcpClient.GetData(message) ' get data from server txtOutput.Text = txtOutput.Text & message & vbCrLf txtOutput.SelStart = Len(txtOutput.Text) End Sub Private Sub tcpClient_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) ' If the client fails to connect to server, then this code executes Dim result As Integer result = MsgBox(Source & ": " & Description & vbCrLf & "Doh! Can't connect to server!", _ vbOKOnly, "TCP/IP Error") ' Source variable is the control (winsock in this case) causing the error ' Description variable cites the error message ' vbOKOnly is the control button ' TCP/IP Error is the MsgBox caption End End Sub