home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / internet / vbipsmtp / echo.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-08-16  |  12.3 KB  |  361 lines

  1. VERSION 2.00
  2. Begin Form frmMain 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   3  'Fixed Double
  5.    Caption         =   "Echo Sample Application"
  6.    ClientHeight    =   5820
  7.    ClientLeft      =   4620
  8.    ClientTop       =   2565
  9.    ClientWidth     =   4545
  10.    FontBold        =   -1  'True
  11.    FontItalic      =   0   'False
  12.    FontName        =   "Arial"
  13.    FontSize        =   8.25
  14.    FontStrikethru  =   0   'False
  15.    FontUnderline   =   0   'False
  16.    Height          =   6225
  17.    Icon            =   ECHO.FRX:0000
  18.    Left            =   4560
  19.    LinkTopic       =   "Form1"
  20.    MaxButton       =   0   'False
  21.    ScaleHeight     =   5820
  22.    ScaleWidth      =   4545
  23.    Top             =   2220
  24.    Width           =   4665
  25.    Begin PictureBox Picture1 
  26.       BackColor       =   &H00C0C0C0&
  27.       BorderStyle     =   0  'None
  28.       Height          =   1065
  29.       Left            =   105
  30.       ScaleHeight     =   1065
  31.       ScaleWidth      =   4425
  32.       TabIndex        =   3
  33.       Top             =   630
  34.       Width           =   4425
  35.       Begin OptionButton opServerAddress 
  36.          BackColor       =   &H00C0C0C0&
  37.          Caption         =   "Use Server Address"
  38.          FontBold        =   0   'False
  39.          FontItalic      =   0   'False
  40.          FontName        =   "MS Sans Serif"
  41.          FontSize        =   8.25
  42.          FontStrikethru  =   0   'False
  43.          FontUnderline   =   0   'False
  44.          Height          =   225
  45.          Left            =   2310
  46.          TabIndex        =   9
  47.          Top             =   735
  48.          Width           =   2115
  49.       End
  50.       Begin OptionButton opServerName 
  51.          BackColor       =   &H00C0C0C0&
  52.          Caption         =   "Use Server Name"
  53.          FontBold        =   0   'False
  54.          FontItalic      =   0   'False
  55.          FontName        =   "MS Sans Serif"
  56.          FontSize        =   8.25
  57.          FontStrikethru  =   0   'False
  58.          FontUnderline   =   0   'False
  59.          Height          =   225
  60.          Left            =   210
  61.          TabIndex        =   8
  62.          Top             =   735
  63.          Value           =   -1  'True
  64.          Width           =   1905
  65.       End
  66.       Begin TextBox txServerAddress 
  67.          BackColor       =   &H00FFFFFF&
  68.          Height          =   285
  69.          Left            =   1575
  70.          TabIndex        =   7
  71.          Top             =   315
  72.          Width           =   2745
  73.       End
  74.       Begin TextBox txServerName 
  75.          BackColor       =   &H00FFFFFF&
  76.          Height          =   285
  77.          Left            =   1575
  78.          TabIndex        =   6
  79.          Top             =   0
  80.          Width           =   2745
  81.       End
  82.       Begin Label Label2 
  83.          Alignment       =   1  'Right Justify
  84.          BackColor       =   &H00C0C0C0&
  85.          Caption         =   "Server Address :"
  86.          FontBold        =   0   'False
  87.          FontItalic      =   0   'False
  88.          FontName        =   "MS Sans Serif"
  89.          FontSize        =   8.25
  90.          FontStrikethru  =   0   'False
  91.          FontUnderline   =   0   'False
  92.          Height          =   225
  93.          Left            =   0
  94.          TabIndex        =   5
  95.          Top             =   315
  96.          Width           =   1485
  97.       End
  98.       Begin Label Label1 
  99.          Alignment       =   1  'Right Justify
  100.          BackColor       =   &H00C0C0C0&
  101.          Caption         =   "Server Name :"
  102.          FontBold        =   0   'False
  103.          FontItalic      =   0   'False
  104.          FontName        =   "MS Sans Serif"
  105.          FontSize        =   8.25
  106.          FontStrikethru  =   0   'False
  107.          FontUnderline   =   0   'False
  108.          Height          =   225
  109.          Left            =   0
  110.          TabIndex        =   4
  111.          Top             =   0
  112.          Width           =   1485
  113.       End
  114.    End
  115.    Begin dsSocket dsSocket1 
  116.       DataSize        =   2048
  117.       EOLChar         =   0
  118.       Left            =   3840
  119.       LineMode        =   0   'False
  120.       Linger          =   -1  'True
  121.       LocalPort       =   0
  122.       RemoteDotAddr   =   ""
  123.       RemoteHost      =   ""
  124.       RemotePort      =   0
  125.       ServiceName     =   ""
  126.       Timeout         =   10
  127.       Top             =   1920
  128.    End
  129.    Begin TextBox txStatus 
  130.       BackColor       =   &H00C0C0C0&
  131.       FontBold        =   0   'False
  132.       FontItalic      =   0   'False
  133.       FontName        =   "MS Sans Serif"
  134.       FontSize        =   8.25
  135.       FontStrikethru  =   0   'False
  136.       FontUnderline   =   0   'False
  137.       Height          =   330
  138.       Left            =   105
  139.       TabIndex        =   14
  140.       Top             =   5355
  141.       Width           =   4320
  142.    End
  143.    Begin CommandButton btnEcho 
  144.       Caption         =   "&Echo"
  145.       FontBold        =   0   'False
  146.       FontItalic      =   0   'False
  147.       FontName        =   "MS Sans Serif"
  148.       FontSize        =   8.25
  149.       FontStrikethru  =   0   'False
  150.       FontUnderline   =   0   'False
  151.       Height          =   330
  152.       Left            =   180
  153.       TabIndex        =   0
  154.       Top             =   3045
  155.       Width           =   1275
  156.    End
  157.    Begin ListBox lbEcho 
  158.       BackColor       =   &H00C0C0C0&
  159.       FontBold        =   0   'False
  160.       FontItalic      =   0   'False
  161.       FontName        =   "MS Sans Serif"
  162.       FontSize        =   8.25
  163.       FontStrikethru  =   0   'False
  164.       FontUnderline   =   0   'False
  165.       Height          =   1590
  166.       Left            =   105
  167.       TabIndex        =   1
  168.       Top             =   3675
  169.       Width           =   4320
  170.    End
  171.    Begin TextBox txData 
  172.       BackColor       =   &H00FFFFFF&
  173.       FontBold        =   0   'False
  174.       FontItalic      =   0   'False
  175.       FontName        =   "MS Sans Serif"
  176.       FontSize        =   8.25
  177.       FontStrikethru  =   0   'False
  178.       FontUnderline   =   0   'False
  179.       Height          =   750
  180.       Left            =   1575
  181.       TabIndex        =   13
  182.       Text            =   "This is a sample of echo data."
  183.       Top             =   2625
  184.       Width           =   2850
  185.    End
  186.    Begin OptionButton opServiceNumber 
  187.       BackColor       =   &H00C0C0C0&
  188.       Caption         =   "Use echo Port Number (7)"
  189.       FontBold        =   0   'False
  190.       FontItalic      =   0   'False
  191.       FontName        =   "MS Sans Serif"
  192.       FontSize        =   8.25
  193.       FontStrikethru  =   0   'False
  194.       FontUnderline   =   0   'False
  195.       Height          =   225
  196.       Left            =   315
  197.       TabIndex        =   11
  198.       Top             =   2300
  199.       Value           =   -1  'True
  200.       Width           =   2535
  201.    End
  202.    Begin OptionButton opServiceName 
  203.       BackColor       =   &H00C0C0C0&
  204.       Caption         =   "Use echo Service Name"
  205.       FontBold        =   0   'False
  206.       FontItalic      =   0   'False
  207.       FontName        =   "MS Sans Serif"
  208.       FontSize        =   8.25
  209.       FontStrikethru  =   0   'False
  210.       FontUnderline   =   0   'False
  211.       Height          =   225
  212.       Left            =   315
  213.       TabIndex        =   10
  214.       Top             =   2000
  215.       Width           =   2535
  216.    End
  217.    Begin Label Label4 
  218.       BackColor       =   &H00C0C0C0&
  219.       Caption         =   "Echo from server :"
  220.       FontBold        =   0   'False
  221.       FontItalic      =   0   'False
  222.       FontName        =   "MS Sans Serif"
  223.       FontSize        =   8.25
  224.       FontStrikethru  =   0   'False
  225.       FontUnderline   =   0   'False
  226.       Height          =   225
  227.       Left            =   105
  228.       TabIndex        =   2
  229.       Top             =   3465
  230.       Width           =   1905
  231.    End
  232.    Begin Label Label3 
  233.       Alignment       =   1  'Right Justify
  234.       BackColor       =   &H00C0C0C0&
  235.       Caption         =   "Data to echo :"
  236.       FontBold        =   0   'False
  237.       FontItalic      =   0   'False
  238.       FontName        =   "MS Sans Serif"
  239.       FontSize        =   8.25
  240.       FontStrikethru  =   0   'False
  241.       FontUnderline   =   0   'False
  242.       Height          =   225
  243.       Left            =   105
  244.       TabIndex        =   12
  245.       Top             =   2625
  246.       Width           =   1380
  247.    End
  248. Option Explicit
  249. '   Declare the constants used to set the Action property
  250. '   and check the State of the socket
  251. Const SOCK_ACTION_CLOSE = 1
  252. Const SOCK_ACTION_CONNECT = 2
  253. Const SOCK_ACTION_LISTEN = 3
  254. Const SOCK_STATE_CLOSED = 1
  255. Const SOCK_STATE_CONNECTED = 2
  256. Sub btnEcho_Click ()
  257.     '   Setup to handle errors as they occur
  258.     On Error Resume Next
  259.     '   If the user selected to use the ServerName, then
  260.     '   set the properties accordingly.  If RemoteDotAddr is
  261.     '   blank, then the control will use the RemoteHost information
  262.     '   to resolve an address.
  263.     If (opServerName) Then
  264.         dsSocket1.RemoteHost = txServerName.Text
  265.         dsSocket1.RemoteDotAddr = ""
  266.     Else
  267.         dsSocket1.RemoteHost = ""
  268.         dsSocket1.RemoteDotAddr = txServerAddress.Text
  269.     End If
  270.     '   If the user selected to use the ServiceName, then
  271.     '   set the properties accordingly.  If RemotePort property is
  272.     '   zero, then the control will use the ServiceName information
  273.     '   to resolve a port number for making the connection.
  274.     If (opServiceName) Then
  275.         dsSocket1.ServiceName = "echo"  ' set service name to "echo"
  276.         dsSocket1.RemotePort = 0
  277.     Else
  278.         dsSocket1.ServiceName = ""
  279.         dsSocket1.RemotePort = 7    ' standard TCP port number for echo
  280.                                     ' as defined in SERVICES file
  281.     End If
  282.     '   If the socket is not already connected, the do a Connect
  283.     If (dsSocket1.State = SOCK_STATE_CLOSED) Then
  284.         
  285.         '   show the status information
  286.         txStatus.Text = "Connecting to server..."
  287.         
  288.         '   issue the connect command
  289.         dsSocket1.Action = SOCK_ACTION_CONNECT
  290.         
  291.         '   if there were any errors establishing the connection
  292.         '   then report them
  293.         If (Err > 0) Then
  294.             MsgBox "Error attempting connect to server." & Chr(13) & Format(Err) & " : " & Error
  295.             txStatus.Text = Error & "..."
  296.             Exit Sub
  297.         
  298.         End If
  299.     End If
  300. End Sub
  301. Sub dsSocket1_Connect ()
  302.     txStatus.Text = "Connected to server " + txServerName.Text + "..."
  303. End Sub
  304. Sub dsSocket1_Receive (ReceiveData As String)
  305.     '
  306.     '   Process data echoed back from server
  307.     '
  308.     On Error Resume Next
  309.     '   Display the data in the listbox
  310.     lbEcho.AddItem ReceiveData
  311.     '   Make the last item the current one
  312.     lbEcho.ListIndex = lbEcho.ListCount - 1
  313.     '   Close the connection.  Normally this wouldn't be done
  314.     '   until we are actually finished with the connection.  We
  315.     '   do it here for demonstration purposes
  316.     dsSocket1.Action = SOCK_ACTION_CLOSE
  317.     '   If there were any errors then report them.  The Action property
  318.     '   will return errors in the standard VB error variables
  319.     If (Err > 0) Then
  320.         MsgBox "Error disconnecting from server." & Chr(13) & Format(Err) & " : " & Error
  321.         txStatus.Text = Error & "..."
  322.         Exit Sub
  323.     '   If no errors, just report the status
  324.     Else
  325.         txStatus.Text = "Disconnected from server " + txServerName.Text + "..."
  326.     End If
  327. End Sub
  328. Sub dsSocket1_SendReady ()
  329.     '   now that the socket is connected, send the data string to be echoed back
  330.     dsSocket1.Send = txData.Text
  331.     '   if there were any errors establishing the connection
  332.     '   then report them
  333.     If (Err > 0) Then
  334.         MsgBox "Error sending data to server." & Chr(13) & Format(Err) & " : " & Error
  335.         txStatus.Text = Error & "..."
  336.     '   else show the status
  337.     Else
  338.         txStatus.Text = Format(Len(txData.Text)) + " bytes sent to server..."
  339.     End If
  340. End Sub
  341. Sub Form_Paint ()
  342.     '
  343.     '   This is simply some pretty header code
  344.     '
  345.     '   Setup to do a shadowed text title and copyright notice.
  346.     FontSize = 30
  347.     FontItalic = True
  348.     Forecolor = &H808080
  349.     CurrentX = 140
  350.     CurrentY = -50
  351.     Print "Echo"
  352.     Forecolor = &HFF0000
  353.     CurrentX = 170
  354.     CurrentY = -20
  355.     Print "Echo"
  356.     FontSize = 12
  357.     CurrentX = 1800
  358.     CurrentY = 300
  359.     Print Chr(169) & "Dolphin Systems Inc."
  360. End Sub
  361.