home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Object = "{C7212F93-30E8-11D2-B450-0020AFD69DE6}#1.0#0"; "SocketX.OCX"
- Begin VB.MDIForm MDIForm1
- Appearance = 0 'Flat
- BackColor = &H8000000C&
- Caption = "Socket Server"
- ClientHeight = 6405
- ClientLeft = 3135
- ClientTop = 3360
- ClientWidth = 8340
- LinkTopic = "MDIForm1"
- Begin VB.PictureBox Picture1
- Align = 1 'Align Top
- Appearance = 0 'Flat
- BackColor = &H00C0C0C0&
- BorderStyle = 0 'None
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 8.25
- Charset = 0
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- ForeColor = &H80000008&
- Height = 1515
- Left = 0
- ScaleHeight = 1515
- ScaleWidth = 8340
- TabIndex = 0
- Top = 0
- Width = 8340
- Begin SocketXCtl.SocketXCtl SocketX
- Left = 360
- Top = 720
- AcceptTimeout = 0
- BlockingMode = -842150451
- Blocking = -1 'True
- BroadcastEnabled= -1 'True
- ConnectTimeout = 0
- EventMask = 63
- KeepAliveEnabled= 0 'False
- LibraryName = "WSOCK32.DLL"
- LingerEnabled = 0 'False
- LingerMode = 0
- LingerTime = 0
- LocalAddress = "123.123.123.123"
- LocalPort = 0
- OutOfBandEnabled= 0 'False
- ReceiveBufferSize= 8192
- ReceiveTimeout = 0
- RemoteAddress = ""
- RemoteName = ""
- ReuseAddressEnabled= 0 'False
- RemotePort = 0
- RouteEnabled = -1 'True
- SendTimeout = 0
- SendBufferSize = 8192
- SocketType = 0
- TcpNoDelayEnabled= 0 'False
- End
- Begin VB.Timer Timer1
- Enabled = 0 'False
- Interval = 1000
- Left = 7650
- Top = 780
- End
- Begin VB.TextBox textLocalAddress
- Appearance = 0 'Flat
- Height = 285
- Left = 1335
- TabIndex = 3
- Text = "0.0.0.0"
- Top = 135
- Width = 1425
- End
- Begin VB.TextBox textLocalPort
- Appearance = 0 'Flat
- Height = 285
- Left = 3870
- TabIndex = 2
- Text = "0"
- Top = 135
- Width = 555
- End
- Begin VB.ListBox listStatus
- Appearance = 0 'Flat
- Height = 810
- Left = 1335
- TabIndex = 1
- Top = 465
- Width = 6120
- End
- Begin VB.Line Line2
- BorderColor = &H00FFFFFF&
- X1 = 0
- X2 = 8415
- Y1 = 90
- Y2 = 90
- End
- Begin VB.Line Line1
- BorderColor = &H00404040&
- BorderWidth = 2
- X1 = 15
- X2 = 7785
- Y1 = 1380
- Y2 = 1380
- End
- Begin VB.Label Label1
- Alignment = 1 'Right Justify
- Appearance = 0 'Flat
- BackColor = &H00C0C0C0&
- Caption = "Local Address:"
- ForeColor = &H80000008&
- Height = 225
- Index = 0
- Left = 165
- TabIndex = 6
- Top = 150
- Width = 1155
- End
- Begin VB.Label Label1
- Alignment = 1 'Right Justify
- Appearance = 0 'Flat
- BackColor = &H00C0C0C0&
- Caption = "Local Port:"
- ForeColor = &H80000008&
- Height = 210
- Index = 1
- Left = 2940
- TabIndex = 5
- Top = 150
- Width = 840
- End
- Begin VB.Label Label2
- Alignment = 1 'Right Justify
- Appearance = 0 'Flat
- BackColor = &H00C0C0C0&
- Caption = "Status:"
- ForeColor = &H80000008&
- Height = 285
- Left = 435
- TabIndex = 4
- Top = 435
- Width = 855
- End
- End
- Begin VB.Menu FileMenu
- Caption = "&File"
- Begin VB.Menu FileExit
- Caption = "E&xit"
- End
- End
- Begin VB.Menu WindowMenu
- Caption = "&Window"
- WindowList = -1 'True
- End
- Begin VB.Menu HelpMenu
- Caption = "&Help"
- Begin VB.Menu HelpAbout
- Caption = "&About"
- End
- End
- Attribute VB_Name = "MDIForm1"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Option Explicit
- Private Sub SocketX_Accept(ByVal SocketHandle As Long, ByVal ErrorCode As Integer)
- Dim foo As New formSession
- foo.textSocketHandle = CStr(SocketHandle)
- listStatus.AddItem "Accept" & Str(ErrorCode)
- listStatus.AddItem "Socket Address: " & foo.SocketX.SocketAddress
- If Trim$(foo.SocketX.RemoteAddress) <> "" Then
- foo.lblClientIP = foo.SocketX.RemoteAddress
- Else
- foo.lblClientIP = "Unknown IP"
- End If
- foo.lblClientPort = CStr(foo.SocketX.RemotePort)
- End Sub
- Private Sub SocketX_Close(ByVal ErrorCode As Integer)
- listStatus.AddItem "Close" & Str(ErrorCode)
- SocketX.Close
- SocketX.Create
- SocketX.Listen
- End Sub
- Private Sub SocketX_Connect(ByVal ErrorCode As Integer)
- listStatus.AddItem "Connect" & Str(ErrorCode)
- '
- ' Remove all of the following lines if you have a known
- ' address.
- '
- SocketX.LocalPort = 0
- SocketX.LocalAddress = SocketX.SocketAddress
- textLocalAddress = SocketX.SocketAddress
- textLocalPort = SocketX.SocketPort
- SocketX.Close
- SocketX.Create
- SocketX.Listen
- listStatus.AddItem "Done determining local address"
- End Sub
- Private Sub MDIForm_Load()
- Me.Show
- listStatus.AddItem "Determining local address, please wait"
- DoEvents
- '
- ' note: When running as a client on a service which
- ' provides you with an ip address when you connect the
- ' program must go through some hoops to get the assigned
- ' ip address to use with this server example.
- '
- ' This sample program was tested on such a server and
- ' handles the problem. For a _real_ server this is
- ' somewhat unrealistic since a real server would
- ' be expected to have a known address and presumably
- ' you would know what that address is.
- '
- SocketX.Blocking = False
- SocketX.EventMask = -1
- SocketX.LocalPort = 0
- SocketX.LocalAddress = "0.0.0.0"
- '
- ' Winsock won't tell us what our ip address is until
- ' after we connect to some remote socket. Here I've
- ' chosen to use mit.edu.
- '
- SocketX.RemotePort = 13
- '
- ' If you can't do name lookups comment out the following
- ' three lines and uncomment the one following them.
- '
- ' Also, if you have a known server address then remove
- ' the following three lines, uncomment the fourth, and
- ' supply the appropriate address there. Be sure to remove
- ' the indicated lines in OnConnect as well in this case.
- '
- SocketX.RemoteNameAddrXlate = True
- SocketX.RemoteName = "mit.edu"
- SocketX.RemoteNameAddrXlate = False
- ' SocketX.RemoteAddress = "18.72.2.1"
- SocketX.Create
- On Error Resume Next
- '
- ' Remove the following 5 lines if you have a known address
- '
- SocketX.Connect
- If (Err <> 0 And Err <> 10035) Then
- MsgBox Error
- End If
- On Error GoTo 0
- '
- ' Uncomment the following two lines if you have a known
- ' address.
- '
- 'SocketX.Action = ASocketCreate
- 'SocketX.Action = ASocketListen
- End Sub
- Private Sub MDIForm_Resize()
- Line1.Y1 = Picture1.Height - Screen.TwipsPerPixelY
- Line1.Y2 = Line1.Y1
- Line2.Y1 = 0
- Line2.Y2 = 0
- Line1.X1 = 0
- Line1.X2 = Picture1.Width
- Line2.X1 = 0
- Line2.X2 = Picture1.Width
- listStatus.Width = Me.ScaleWidth - (listStatus.Left + 5 * Screen.TwipsPerPixelX)
- End Sub
-