home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / netsnake / frmmain.frm (.txt) next >
Encoding:
Visual Basic Form  |  1999-07-27  |  4.7 KB  |  162 lines

  1. VERSION 5.00
  2. Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
  3. Begin VB.Form frmMain 
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "NetSnake"
  6.    ClientHeight    =   5865
  7.    ClientLeft      =   3315
  8.    ClientTop       =   1455
  9.    ClientWidth     =   10725
  10.    Icon            =   "frmMain.frx":0000
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    ScaleHeight     =   5865
  14.    ScaleWidth      =   10725
  15.    Begin VB.Timer timeOut 
  16.       Enabled         =   0   'False
  17.       Interval        =   60000
  18.       Left            =   840
  19.       Top             =   1920
  20.    End
  21.    Begin MSWinsockLib.Winsock Winout 
  22.       Left            =   4800
  23.       Top             =   1680
  24.       _ExtentX        =   741
  25.       _ExtentY        =   741
  26.       _Version        =   393216
  27.    End
  28.    Begin MSWinsockLib.Winsock Winin 
  29.       Left            =   4440
  30.       Top             =   1680
  31.       _ExtentX        =   741
  32.       _ExtentY        =   741
  33.       _Version        =   393216
  34.    End
  35.    Begin VB.ListBox lstLog 
  36.       Height          =   5910
  37.       Left            =   0
  38.       TabIndex        =   0
  39.       Top             =   0
  40.       Width           =   10695
  41.    End
  42. Attribute VB_Name = "frmMain"
  43. Attribute VB_GlobalNameSpace = False
  44. Attribute VB_Creatable = False
  45. Attribute VB_PredeclaredId = True
  46. Attribute VB_Exposed = False
  47. Private Sub Form_Load()
  48. On Error GoTo errorHandle
  49. If Command = "" Then End
  50. App.TaskVisible = False
  51. Me.Show
  52. DoEvents
  53. Dim newCom As String
  54. Dim LBuffer As String * 3000
  55. Dim posCount As Long
  56. newCom = Trim(LCase(Command))
  57. lstLog.AddItem newCom
  58. lstLog.AddItem "mode: " & Parse(newCom, 1)
  59. Select Case Parse(newCom, 1)
  60.     Case "in"
  61.         Winin.LocalPort = CInt(Val(Parse(newCom, 2)))
  62.         Winin.Listen
  63.         lstLog.AddItem "listening on port " & Winin.LocalPort
  64.         timeOut.Enabled = True
  65.         
  66.     Case "out"
  67.         Winout.RemoteHost = Parse(newCom, 2)
  68.         Winout.RemotePort = CInt(Val(Parse(newCom, 3)))
  69.         outFile = Parse(newCom, 4)
  70.         inFile = Parse(newCom, 5)
  71.         'check file
  72.         If Dir(outFile) = "" Then End
  73.         'end check file
  74.         Winout.Connect
  75.         lstLog.AddItem "connecting to " & Winout.RemoteHost & ":" & Winout.RemotePort
  76.         lstLog.AddItem "task: send file " & outFile & " -> " & inFile
  77.         'wait for connection
  78.         timeOut.Enabled = True
  79.         Do While Winout.State <> sckConnected: DoEvents: Loop
  80.         timeOut.Enabled = False
  81.         'start doing stuff
  82.         Winout.SendData READY
  83.         WaitFor READY
  84.         Winout.SendData IN_FILENAME & inFile
  85.         WaitFor GOT_FILENAME
  86.                 
  87.         Open outFile For Binary As #1
  88.         LBuffer = ""
  89.         Do While Not EOF(1)
  90.             fullCount = fullCount + 1
  91.             Get #1, , LBuffer
  92.             Winout.SendData IN_DATA & LBuffer
  93.             WaitFor RECEIVED
  94.             Response = ""
  95.             Me.Caption = (fullCount * 3001)
  96.             DoEvents
  97.         Loop
  98.         Close #1
  99.         Winout.SendData DONE
  100.         lstLog.AddItem "DONE"
  101.         timeOut.Enabled = True
  102.     Case Else
  103.         lstLog.AddItem "INVALID MODE"
  104.         End
  105. End Select
  106. Exit Sub
  107. errorHandle:
  108. On Error Resume Next
  109. Open "c:\nslog.log" For Append As #2
  110.     Print #2, Err.Number & " - "; Err.Description
  111. Close #2
  112. End Sub
  113. Private Sub Form_Unload(Cancel As Integer)
  114. End Sub
  115. Private Sub timeOut_Timer()
  116. lstLog.AddItem "TIMEOUT"
  117. End Sub
  118. Private Sub Winin_ConnectionRequest(ByVal requestID As Long)
  119. Winin.Close
  120. DoEvents
  121. Winin.Accept requestID
  122. End Sub
  123. Private Sub Winin_DataArrival(ByVal bytesTotal As Long)
  124. timeOut.Enabled = False
  125. Dim cOm As String
  126. Dim writeData As String * 3001
  127. Winin.GetData Response
  128. Data = Right(Response, (Len(Response) - 1))
  129. cOm = Left(Response, 1)
  130. Select Case cOm
  131.     Case BUFFER
  132.     Case READY
  133.         Winin.SendData READY
  134.         lstLog.AddItem "SENT READY SIGNAL"
  135.     Case IN_FILENAME
  136.         inFile = Data
  137.         Winin.SendData GOT_FILENAME
  138.         lstLog.AddItem "INPUT FILE SET " & inFile
  139.     Case IN_DATA
  140.         On Error Resume Next
  141.         writeData = Data
  142.         Open inFile For Binary As #1
  143.             Seek #1, LOF(1)
  144.             Put #1, , writeData
  145.         Close #1
  146.         fullCount = fullCount + 1
  147.         Me.Caption = (fullCount * 3001): DoEvents 'log bytes received
  148.         Winin.SendData RECEIVED
  149.     Case DONE
  150.         Winin.Close
  151.         lstLog.AddItem "DONE"
  152.         timeOut.Enabled = True
  153. End Select
  154. Response = ""
  155. timeOut.Enabled = True
  156. End Sub
  157. Private Sub Winout_DataArrival(ByVal bytesTotal As Long)
  158. timeOut.Enabled = False
  159. Winout.GetData Response
  160. timeOut.Enabled = True
  161. End Sub
  162.