VERSION 5.00 Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX" Begin VB.Form frmLEDClient BackColor = &H00C0C000& Caption = "Simple TCP Client" ClientHeight = 3765 ClientLeft = 60 ClientTop = 345 ClientWidth = 6480 LinkTopic = "Form1" ScaleHeight = 3765 ScaleWidth = 6480 StartUpPosition = 3 'Windows Default Begin VB.CommandButton cmdSeven BackColor = &H00C0C0C0& Caption = "7" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 5520 TabIndex = 9 Top = 480 Width = 495 End Begin VB.CommandButton cmdSix BackColor = &H00C0C0C0& Caption = "6" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 4800 TabIndex = 8 Top = 480 Width = 495 End Begin VB.CommandButton cmdZero BackColor = &H00C0C0C0& Caption = "0" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 480 TabIndex = 7 Top = 480 Width = 495 End Begin VB.CommandButton cmdFive BackColor = &H00C0C0C0& Caption = "5" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 4080 TabIndex = 6 Top = 480 Width = 495 End Begin VB.CommandButton cmdFour BackColor = &H00C0C0C0& Caption = "4" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 3360 TabIndex = 5 Top = 480 Width = 495 End Begin VB.CommandButton cmdThree BackColor = &H00C0C0C0& Caption = "3" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 2640 TabIndex = 4 Top = 480 Width = 495 End Begin VB.CommandButton cmdTwo BackColor = &H00C0C0C0& Caption = "2" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 1920 TabIndex = 3 Top = 480 Width = 495 End Begin VB.CommandButton cmdOne BackColor = &H00C0C0C0& Caption = "1" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 1200 TabIndex = 2 Top = 480 Width = 495 End Begin VB.TextBox txtOutput Height = 2295 Left = 360 MultiLine = -1 'True ScrollBars = 2 'Vertical TabIndex = 0 Top = 1320 Width = 5775 End Begin MSWinsockLib.Winsock tcpClient Left = 4320 Top = 0 _ExtentX = 741 _ExtentY = 741 _Version = 393216 End Begin VB.Label lblSelectButton BackColor = &H00C0C000& Caption = "Click a button" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H0000FFFF& Height = 255 Left = 2880 TabIndex = 10 Top = 120 Width = 1455 End Begin VB.Label lblTextOutput BackColor = &H00C0C000& 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 = &H0000FFFF& Height = 255 Left = 480 TabIndex = 1 Top = 1080 Width = 1575 End End Attribute VB_Name = "frmLEDClient" 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 cmdFive_Click() ' Send five to server Call tcpClient.SendData("5") txtOutput.Text = txtOutput.Text & _ "Client clicked 5" & vbCrLf txtOutput.SelStart = Len(txtOutput.Text) End Sub Private Sub cmdFour_Click() ' Send four to server Call tcpClient.SendData("4") txtOutput.Text = txtOutput.Text & _ "Client clicked 4" & vbCrLf txtOutput.SelStart = Len(txtOutput.Text) End Sub Private Sub cmdOne_Click() ' Send one to server Call tcpClient.SendData("1") txtOutput.Text = txtOutput.Text & _ "Client clicked 1" & vbCrLf txtOutput.SelStart = Len(txtOutput.Text) End Sub Private Sub cmdSeven_Click() ' Send seven to server Call tcpClient.SendData("7") txtOutput.Text = txtOutput.Text & _ "Client clicked 7" & vbCrLf txtOutput.SelStart = Len(txtOutput.Text) End Sub Private Sub cmdSix_Click() ' Send six to server Call tcpClient.SendData("6") txtOutput.Text = txtOutput.Text & _ "Client clicked 6" & vbCrLf txtOutput.SelStart = Len(txtOutput.Text) End Sub Private Sub cmdThree_Click() ' Send three to server Call tcpClient.SendData("3") txtOutput.Text = txtOutput.Text & _ "Client clicked 3" & vbCrLf txtOutput.SelStart = Len(txtOutput.Text) End Sub Private Sub cmdTwo_Click() ' Send two to server Call tcpClient.SendData("2") txtOutput.Text = txtOutput.Text & _ "Client clicked 2" & vbCrLf txtOutput.SelStart = Len(txtOutput.Text) End Sub Private Sub cmdZero_Click() ' Send zero to server Call tcpClient.SendData("0") txtOutput.Text = txtOutput.Text & _ "Client clicked 0" & 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