home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / socketx / CLIENT32.FRM (.txt) next >
Encoding:
Visual Basic Form  |  1998-10-06  |  5.1 KB  |  167 lines

  1. VERSION 5.00
  2. Object = "{C7212F93-30E8-11D2-B450-0020AFD69DE6}#1.0#0"; "SocketX.OCX"
  3. Begin VB.Form Form1 
  4.    BorderStyle     =   3  'Fixed Dialog
  5.    Caption         =   "Socket Client"
  6.    ClientHeight    =   4005
  7.    ClientLeft      =   1515
  8.    ClientTop       =   1950
  9.    ClientWidth     =   8490
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    PaletteMode     =   1  'UseZOrder
  14.    ScaleHeight     =   4005
  15.    ScaleWidth      =   8490
  16.    ShowInTaskbar   =   0   'False
  17.    Begin SocketXCtl.SocketXCtl SocketX 
  18.       Left            =   240
  19.       Top             =   3240
  20.       _cx             =   847
  21.       _cy             =   847
  22.       AcceptTimeout   =   0
  23.       BlockingMode    =   -842150451
  24.       Blocking        =   -1  'True
  25.       BroadcastEnabled=   -1  'True
  26.       ConnectTimeout  =   0
  27.       EventMask       =   63
  28.       KeepAliveEnabled=   0   'False
  29.       LibraryName     =   "WSOCK32.DLL"
  30.       LingerEnabled   =   0   'False
  31.       LingerMode      =   0
  32.       LingerTime      =   0
  33.       LocalAddress    =   ""
  34.       LocalPort       =   0
  35.       OutOfBandEnabled=   0   'False
  36.       ReceiveBufferSize=   8192
  37.       ReceiveTimeout  =   0
  38.       RemoteAddress   =   ""
  39.       RemoteName      =   ""
  40.       ReuseAddressEnabled=   0   'False
  41.       RemotePort      =   0
  42.       RouteEnabled    =   -1  'True
  43.       SendTimeout     =   0
  44.       SendBufferSize  =   8192
  45.       SocketType      =   0
  46.       TcpNoDelayEnabled=   0   'False
  47.    End
  48.    Begin VB.TextBox textMessageEntry 
  49.       Height          =   900
  50.       Left            =   1560
  51.       TabIndex        =   0
  52.       Top             =   2475
  53.       Width           =   5055
  54.    End
  55.    Begin VB.ListBox listTranscript 
  56.       Height          =   1815
  57.       Left            =   240
  58.       MultiSelect     =   1  'Simple
  59.       TabIndex        =   3
  60.       TabStop         =   0   'False
  61.       Top             =   330
  62.       Width           =   6375
  63.    End
  64.    Begin VB.Label Label2 
  65.       Alignment       =   1  'Right Justify
  66.       Caption         =   "Enter Message and Press Enter:"
  67.       Height          =   570
  68.       Left            =   240
  69.       TabIndex        =   1
  70.       Top             =   2445
  71.       Width           =   1215
  72.    End
  73.    Begin VB.Line Line2 
  74.       BorderColor     =   &H00808080&
  75.       X1              =   240
  76.       X2              =   6600
  77.       Y1              =   2310
  78.       Y2              =   2310
  79.    End
  80.    Begin VB.Line Line1 
  81.       BorderColor     =   &H00FFFFFF&
  82.       X1              =   240
  83.       X2              =   6600
  84.       Y1              =   2340
  85.       Y2              =   2340
  86.    End
  87.    Begin VB.Label Label1 
  88.       Caption         =   "Transcript:"
  89.       Height          =   225
  90.       Left            =   240
  91.       TabIndex        =   2
  92.       Top             =   75
  93.       Width           =   900
  94.    End
  95. Attribute VB_Name = "Form1"
  96. Attribute VB_GlobalNameSpace = False
  97. Attribute VB_Creatable = False
  98. Attribute VB_PredeclaredId = True
  99. Attribute VB_Exposed = False
  100. Option Explicit
  101. Private Sub SocketX_Close(ByVal ErrorCode As Integer)
  102.    ' Close the program if our server goes away
  103.    Unload Me
  104. End Sub
  105. Private Sub SocketX_Receive(ByVal ErrorCode As Integer)
  106.    Dim t As String
  107.    ' Get the text received
  108.    t = SocketX.Receive
  109.    ' If all we have is a carriage return ...
  110.    If (Len(t) = 1 And Asc(Left(t, 1)) = 13) Then
  111.       ' ... just use a blank string.
  112.       t = ""
  113.    End If
  114.       
  115.    ' Add our new string to the transcript
  116.    listTranscript.AddItem t
  117.    listTranscript.ListIndex = listTranscript.ListCount - 1
  118. End Sub
  119. Private Sub Form_Load()
  120.    Me.Show
  121.    SocketX.Blocking = False
  122.    MsgBox "You must run the Server32 sample program before running this program. If you have not already done so please run it now."
  123.    ' Get the server's IP address.
  124.    frmEnterIP.Show 1
  125.    ' If the user pressed Esc/Cancel exit.
  126.    If SocketX.RemoteAddress = "" Then
  127.       End
  128.    End If
  129.    ' Set up the socket control.
  130.    SocketX.RemoteNameAddrXlate = False
  131.    SocketX.RemotePort = 0
  132.    SocketX.LocalAddress = "0.0.0.0"
  133.    SocketX.LocalPort = 0
  134.    SocketX.Create
  135.    ' Connect to the server.
  136.    On Error Resume Next
  137.    SocketX.Connect
  138.    If (Err <> 0 And Err <> 10035) Then
  139.       MsgBox Error
  140.    End If
  141.    On Error GoTo 0
  142. End Sub
  143. Private Sub Form_Unload(Cancel As Integer)
  144.    ' Disconnect from test server
  145.    SocketX.Close
  146. End Sub
  147. Private Sub textMessageEntry_KeyPress(KeyAscii As Integer)
  148.    Dim t As String
  149.    ' Did the user press Enter?
  150.    If (KeyAscii = 13) Then
  151.       t = textMessageEntry.Text
  152.       If (textMessageEntry.Text = "") Then
  153.          t = Chr$(13)
  154.       End If
  155.       '
  156.       ' If you want to send a string containing binary data
  157.       ' you must assign it to SendBuffer and then use Send
  158.       ' without any arguments.  If you use Send strTemp VB
  159.       ' will truncate the string at the first chr$(0) if it
  160.       ' contains any.
  161.       '
  162.       SocketX.Send t
  163.       textMessageEntry.Text = ""
  164.       KeyAscii = 0
  165.    End If
  166. End Sub
  167.