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

  1. VERSION 5.00
  2. Object = "{C7212F93-30E8-11D2-B450-0020AFD69DE6}#1.0#0"; "SocketX.OCX"
  3. Begin VB.MDIForm MDIForm1 
  4.    Appearance      =   0  'Flat
  5.    BackColor       =   &H8000000C&
  6.    Caption         =   "Socket Server"
  7.    ClientHeight    =   6405
  8.    ClientLeft      =   3135
  9.    ClientTop       =   3360
  10.    ClientWidth     =   8340
  11.    LinkTopic       =   "MDIForm1"
  12.    Begin VB.PictureBox Picture1 
  13.       Align           =   1  'Align Top
  14.       Appearance      =   0  'Flat
  15.       BackColor       =   &H00C0C0C0&
  16.       BorderStyle     =   0  'None
  17.       BeginProperty Font 
  18.          Name            =   "MS Sans Serif"
  19.          Size            =   8.25
  20.          Charset         =   0
  21.          Weight          =   700
  22.          Underline       =   0   'False
  23.          Italic          =   0   'False
  24.          Strikethrough   =   0   'False
  25.       EndProperty
  26.       ForeColor       =   &H80000008&
  27.       Height          =   1515
  28.       Left            =   0
  29.       ScaleHeight     =   1515
  30.       ScaleWidth      =   8340
  31.       TabIndex        =   0
  32.       Top             =   0
  33.       Width           =   8340
  34.       Begin SocketXCtl.SocketXCtl SocketX 
  35.          Left            =   360
  36.          Top             =   720
  37.          AcceptTimeout   =   0
  38.          BlockingMode    =   -842150451
  39.          Blocking        =   -1  'True
  40.          BroadcastEnabled=   -1  'True
  41.          ConnectTimeout  =   0
  42.          EventMask       =   63
  43.          KeepAliveEnabled=   0   'False
  44.          LibraryName     =   "WSOCK32.DLL"
  45.          LingerEnabled   =   0   'False
  46.          LingerMode      =   0
  47.          LingerTime      =   0
  48.          LocalAddress    =   "123.123.123.123"
  49.          LocalPort       =   0
  50.          OutOfBandEnabled=   0   'False
  51.          ReceiveBufferSize=   8192
  52.          ReceiveTimeout  =   0
  53.          RemoteAddress   =   ""
  54.          RemoteName      =   ""
  55.          ReuseAddressEnabled=   0   'False
  56.          RemotePort      =   0
  57.          RouteEnabled    =   -1  'True
  58.          SendTimeout     =   0
  59.          SendBufferSize  =   8192
  60.          SocketType      =   0
  61.          TcpNoDelayEnabled=   0   'False
  62.       End
  63.       Begin VB.Timer Timer1 
  64.          Enabled         =   0   'False
  65.          Interval        =   1000
  66.          Left            =   7650
  67.          Top             =   780
  68.       End
  69.       Begin VB.TextBox textLocalAddress 
  70.          Appearance      =   0  'Flat
  71.          Height          =   285
  72.          Left            =   1335
  73.          TabIndex        =   3
  74.          Text            =   "0.0.0.0"
  75.          Top             =   135
  76.          Width           =   1425
  77.       End
  78.       Begin VB.TextBox textLocalPort 
  79.          Appearance      =   0  'Flat
  80.          Height          =   285
  81.          Left            =   3870
  82.          TabIndex        =   2
  83.          Text            =   "0"
  84.          Top             =   135
  85.          Width           =   555
  86.       End
  87.       Begin VB.ListBox listStatus 
  88.          Appearance      =   0  'Flat
  89.          Height          =   810
  90.          Left            =   1335
  91.          TabIndex        =   1
  92.          Top             =   465
  93.          Width           =   6120
  94.       End
  95.       Begin VB.Line Line2 
  96.          BorderColor     =   &H00FFFFFF&
  97.          X1              =   0
  98.          X2              =   8415
  99.          Y1              =   90
  100.          Y2              =   90
  101.       End
  102.       Begin VB.Line Line1 
  103.          BorderColor     =   &H00404040&
  104.          BorderWidth     =   2
  105.          X1              =   15
  106.          X2              =   7785
  107.          Y1              =   1380
  108.          Y2              =   1380
  109.       End
  110.       Begin VB.Label Label1 
  111.          Alignment       =   1  'Right Justify
  112.          Appearance      =   0  'Flat
  113.          BackColor       =   &H00C0C0C0&
  114.          Caption         =   "Local Address:"
  115.          ForeColor       =   &H80000008&
  116.          Height          =   225
  117.          Index           =   0
  118.          Left            =   165
  119.          TabIndex        =   6
  120.          Top             =   150
  121.          Width           =   1155
  122.       End
  123.       Begin VB.Label Label1 
  124.          Alignment       =   1  'Right Justify
  125.          Appearance      =   0  'Flat
  126.          BackColor       =   &H00C0C0C0&
  127.          Caption         =   "Local Port:"
  128.          ForeColor       =   &H80000008&
  129.          Height          =   210
  130.          Index           =   1
  131.          Left            =   2940
  132.          TabIndex        =   5
  133.          Top             =   150
  134.          Width           =   840
  135.       End
  136.       Begin VB.Label Label2 
  137.          Alignment       =   1  'Right Justify
  138.          Appearance      =   0  'Flat
  139.          BackColor       =   &H00C0C0C0&
  140.          Caption         =   "Status:"
  141.          ForeColor       =   &H80000008&
  142.          Height          =   285
  143.          Left            =   435
  144.          TabIndex        =   4
  145.          Top             =   435
  146.          Width           =   855
  147.       End
  148.    End
  149.    Begin VB.Menu FileMenu 
  150.       Caption         =   "&File"
  151.       Begin VB.Menu FileExit 
  152.          Caption         =   "E&xit"
  153.       End
  154.    End
  155.    Begin VB.Menu WindowMenu 
  156.       Caption         =   "&Window"
  157.       WindowList      =   -1  'True
  158.    End
  159.    Begin VB.Menu HelpMenu 
  160.       Caption         =   "&Help"
  161.       Begin VB.Menu HelpAbout 
  162.          Caption         =   "&About"
  163.       End
  164.    End
  165. Attribute VB_Name = "MDIForm1"
  166. Attribute VB_GlobalNameSpace = False
  167. Attribute VB_Creatable = False
  168. Attribute VB_PredeclaredId = True
  169. Attribute VB_Exposed = False
  170. Option Explicit
  171. Private Sub SocketX_Accept(ByVal SocketHandle As Long, ByVal ErrorCode As Integer)
  172.     Dim foo As New formSession
  173.     foo.textSocketHandle = CStr(SocketHandle)
  174.     listStatus.AddItem "Accept" & Str(ErrorCode)
  175.     listStatus.AddItem "Socket Address: " & foo.SocketX.SocketAddress
  176.     If Trim$(foo.SocketX.RemoteAddress) <> "" Then
  177.         foo.lblClientIP = foo.SocketX.RemoteAddress
  178.     Else
  179.         foo.lblClientIP = "Unknown IP"
  180.     End If
  181.     foo.lblClientPort = CStr(foo.SocketX.RemotePort)
  182. End Sub
  183. Private Sub SocketX_Close(ByVal ErrorCode As Integer)
  184.     listStatus.AddItem "Close" & Str(ErrorCode)
  185.     SocketX.Close
  186.     SocketX.Create
  187.     SocketX.Listen
  188. End Sub
  189. Private Sub SocketX_Connect(ByVal ErrorCode As Integer)
  190.     listStatus.AddItem "Connect" & Str(ErrorCode)
  191.     '
  192.     ' Remove all of the following lines if you have a known
  193.     ' address.
  194.     '
  195.     SocketX.LocalPort = 0
  196.     SocketX.LocalAddress = SocketX.SocketAddress
  197.     textLocalAddress = SocketX.SocketAddress
  198.     textLocalPort = SocketX.SocketPort
  199.     SocketX.Close
  200.     SocketX.Create
  201.     SocketX.Listen
  202.     listStatus.AddItem "Done determining local address"
  203. End Sub
  204. Private Sub MDIForm_Load()
  205.     Me.Show
  206.     listStatus.AddItem "Determining local address, please wait"
  207.     DoEvents
  208.     '
  209.     ' note:  When running as a client on a service which
  210.     ' provides you with an ip address when you connect the
  211.     ' program must go through some hoops to get the assigned
  212.     ' ip address to use with this server example.
  213.     '
  214.     ' This sample program was tested on such a server and
  215.     ' handles the problem.  For a _real_ server this is
  216.     ' somewhat unrealistic since a real server would
  217.     ' be expected to have a known address and presumably
  218.     ' you would know what that address is.
  219.     '
  220.     SocketX.Blocking = False
  221.     SocketX.EventMask = -1
  222.     SocketX.LocalPort = 0
  223.     SocketX.LocalAddress = "0.0.0.0"
  224.     '
  225.     ' Winsock won't tell us what our ip address is until
  226.     ' after we connect to some remote socket.  Here I've
  227.     ' chosen to use mit.edu.
  228.     '
  229.     SocketX.RemotePort = 13
  230.     '
  231.     ' If you can't do name lookups comment out the following
  232.     ' three lines and uncomment the one following them.
  233.     '
  234.     ' Also, if you have a known server address then remove
  235.     ' the following three lines, uncomment the fourth, and
  236.     ' supply the appropriate address there.  Be sure to remove
  237.     ' the indicated lines in OnConnect as well in this case.
  238.     '
  239.     SocketX.RemoteNameAddrXlate = True
  240.     SocketX.RemoteName = "mit.edu"
  241.     SocketX.RemoteNameAddrXlate = False
  242.     '    SocketX.RemoteAddress = "18.72.2.1"
  243.     SocketX.Create
  244.     On Error Resume Next
  245.     '
  246.     ' Remove the following 5 lines if you have a known address
  247.     '
  248.     SocketX.Connect
  249.     If (Err <> 0 And Err <> 10035) Then
  250.         MsgBox Error
  251.     End If
  252.     On Error GoTo 0
  253.     '
  254.     ' Uncomment the following two lines if you have a known
  255.     ' address.
  256.     '
  257.     'SocketX.Action = ASocketCreate
  258.     'SocketX.Action = ASocketListen
  259. End Sub
  260. Private Sub MDIForm_Resize()
  261.     Line1.Y1 = Picture1.Height - Screen.TwipsPerPixelY
  262.     Line1.Y2 = Line1.Y1
  263.     Line2.Y1 = 0
  264.     Line2.Y2 = 0
  265.     Line1.X1 = 0
  266.     Line1.X2 = Picture1.Width
  267.     Line2.X1 = 0
  268.     Line2.X2 = Picture1.Width
  269.     listStatus.Width = Me.ScaleWidth - (listStatus.Left + 5 * Screen.TwipsPerPixelX)
  270. End Sub
  271.