home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD1261812122000.psc / Client / Form1.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2000-12-12  |  8.8 KB  |  295 lines

  1. VERSION 5.00
  2. Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
  3. Begin VB.Form Form1 
  4.    Caption         =   "Client"
  5.    ClientHeight    =   4920
  6.    ClientLeft      =   60
  7.    ClientTop       =   345
  8.    ClientWidth     =   3255
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   4920
  11.    ScaleWidth      =   3255
  12.    StartUpPosition =   3  'Windows-Standard
  13.    Begin VB.TextBox txtCommand 
  14.       Height          =   285
  15.       Left            =   120
  16.       TabIndex        =   10
  17.       Top             =   2400
  18.       Width           =   3015
  19.    End
  20.    Begin VB.TextBox txtIP 
  21.       BackColor       =   &H8000000B&
  22.       Enabled         =   0   'False
  23.       Height          =   285
  24.       Left            =   1800
  25.       TabIndex        =   9
  26.       Top             =   960
  27.       Width           =   1335
  28.    End
  29.    Begin VB.OptionButton Option2 
  30.       Caption         =   "Remote IP :"
  31.       Height          =   255
  32.       Left            =   120
  33.       TabIndex        =   8
  34.       Top             =   960
  35.       Width           =   1455
  36.    End
  37.    Begin VB.OptionButton Option1 
  38.       Caption         =   "Remote Host has local IP"
  39.       Height          =   255
  40.       Left            =   120
  41.       TabIndex        =   7
  42.       Top             =   600
  43.       Value           =   -1  'True
  44.       Width           =   3015
  45.    End
  46.    Begin VB.TextBox txtUserName 
  47.       Height          =   285
  48.       Left            =   1800
  49.       TabIndex        =   5
  50.       Top             =   150
  51.       Width           =   1335
  52.    End
  53.    Begin VB.TextBox txtReceived 
  54.       Height          =   1815
  55.       Left            =   120
  56.       MultiLine       =   -1  'True
  57.       TabIndex        =   2
  58.       Top             =   3000
  59.       Width           =   3015
  60.    End
  61.    Begin VB.TextBox txtMessage 
  62.       Enabled         =   0   'False
  63.       Height          =   285
  64.       Left            =   120
  65.       TabIndex        =   1
  66.       Top             =   1800
  67.       Width           =   3015
  68.    End
  69.    Begin MSWinsockLib.Winsock wsMain 
  70.       Left            =   2760
  71.       Top             =   1440
  72.       _ExtentX        =   741
  73.       _ExtentY        =   741
  74.       _Version        =   393216
  75.       RemotePort      =   2400
  76.    End
  77.    Begin VB.CommandButton Command1 
  78.       Caption         =   "Connect"
  79.       Height          =   375
  80.       Left            =   120
  81.       TabIndex        =   0
  82.       Top             =   120
  83.       Width           =   975
  84.    End
  85.    Begin VB.Timer Timer1 
  86.       Enabled         =   0   'False
  87.       Interval        =   10000
  88.       Left            =   120
  89.       Top             =   1440
  90.    End
  91.    Begin VB.Label Label4 
  92.       Alignment       =   2  'Zentriert
  93.       Caption         =   "Send Command"
  94.       Height          =   255
  95.       Left            =   120
  96.       TabIndex        =   11
  97.       Top             =   2160
  98.       Width           =   3015
  99.    End
  100.    Begin VB.Label Label2 
  101.       Alignment       =   2  'Zentriert
  102.       Caption         =   "Send Message"
  103.       Height          =   255
  104.       Left            =   120
  105.       TabIndex        =   4
  106.       Top             =   1560
  107.       Width           =   3015
  108.    End
  109.    Begin VB.Line Line1 
  110.       X1              =   120
  111.       X2              =   3120
  112.       Y1              =   1320
  113.       Y2              =   1320
  114.    End
  115.    Begin VB.Label Label3 
  116.       Caption         =   "Name:"
  117.       Height          =   255
  118.       Left            =   1200
  119.       TabIndex        =   6
  120.       Top             =   180
  121.       Width           =   495
  122.    End
  123.    Begin VB.Label Label1 
  124.       Alignment       =   2  'Zentriert
  125.       Caption         =   "Received From Server"
  126.       Height          =   255
  127.       Left            =   120
  128.       TabIndex        =   3
  129.       Top             =   2760
  130.       Width           =   3015
  131.    End
  132. Attribute VB_Name = "Form1"
  133. Attribute VB_GlobalNameSpace = False
  134. Attribute VB_Creatable = False
  135. Attribute VB_PredeclaredId = True
  136. Attribute VB_Exposed = False
  137. Option Explicit
  138. '------------------------------------------------------------------------------
  139. ' Commands:
  140. '------------------------------------------------------------------------------
  141. ' NewBuffer
  142. ' - Creates a new Buffer for Selections
  143. ' DeleteBuffer|[Key]
  144. ' - Deletes a specified Buffer
  145. ' GetBuffer
  146. ' - Shows the Keys of all existing Buffers
  147. ' Selection|[Key]|[String]
  148. ' - Selects all words in a specified Buffer with wildcard (*) search
  149. ' GetItem|[Key]|[Index]
  150. ' - Gets the value of the specified Buffer and its inde
  151. ' Sample:   NewBuffer
  152. '           Selection|1|A*
  153. '           GetItem|1|1
  154. '           NewBuffer
  155. '           GetBuffer
  156. '           DeleteBuffer|1
  157. '           DeleteBuffer|2
  158. '------------------------------------------------------------------------------
  159. Public server_answer As String
  160. Private Sub Command1_Click()
  161.         
  162.   If Command1.Caption = "Connect" Then
  163.     If txtUserName.Text = "" Then
  164.       MsgBox "You need to type your username!", vbCritical, "Unable to complete"
  165.       Exit Sub
  166.     End If
  167.     If txtIP.Text = "" Then
  168.       MsgBox "IP-Address not valid!"
  169.       Exit Sub
  170.     End If
  171.     wsMain.RemoteHost = txtIP.Text
  172.     wsMain.Connect
  173.     Do Until wsMain.State = 7
  174.       ' 0 is closed, 9 is error
  175.       If wsMain.State = 0 Or wsMain.State = 9 Then
  176.         MsgBox "Error in connecting!", vbCritical, "Winsock Error"
  177.         ' there was an error, so let's leave
  178.         wsMain.Close
  179.         Exit Sub
  180.       End If
  181.       DoEvents  'don't freeze the system!
  182.     Loop
  183.     ' "log-in":
  184.     wsMain.SendData "U" & Chr(1) & txtUserName.Text
  185.     txtUserName.Enabled = False
  186.     txtMessage.Enabled = True
  187.     Command1.Caption = "Disconnect"
  188.       
  189.   Else
  190.     wsMain.Close
  191.     Command1.Caption = "Connect"
  192.     txtReceived = ""
  193.   End If
  194. End Sub
  195. Private Sub Form_Load()
  196.   Call Option1_Click
  197. End Sub
  198. Private Sub Option1_Click()
  199.   Option1.Value = True
  200.   Option2.Value = False
  201.   txtIP.BackColor = &H8000000B
  202.   txtIP.Text = wsMain.LocalIP
  203.   txtIP.Enabled = False
  204. End Sub
  205. Private Sub Option2_Click()
  206.   Option1.Value = False
  207.   Option2.Value = True
  208.   txtIP.BackColor = &H80000005
  209.   txtIP.Text = ""
  210.   txtIP.Enabled = True
  211. End Sub
  212. Private Sub txtCommand_KeyPress(KeyAscii As Integer)
  213.   If KeyAscii = 13 Then
  214.     If wsMain.State = sckConnected Then
  215.       wsMain.SendData "r" & Chr(1) & txtCommand.Text
  216.       txtCommand.Text = ""
  217.       KeyAscii = 0
  218.     Else
  219.       MsgBox "Es existiert momentan keine Verbindung!"
  220.       txtMessage.Text = ""
  221.     End If
  222.   End If
  223. End Sub
  224. Private Sub txtMessage_KeyPress(KeyAscii As Integer)
  225.   If KeyAscii = 13 Then
  226.     If wsMain.State = sckConnected Then
  227.       wsMain.SendData "t" & Chr(1) & txtMessage.Text
  228.       txtMessage.Text = ""
  229.       KeyAscii = 0
  230.     Else
  231.       MsgBox "Es existiert momentan keine Verbindung!"
  232.       txtMessage.Text = ""
  233.     End If
  234.   End If
  235. End Sub
  236. Private Sub wsMain_Close()
  237.         
  238.   txtReceived.SelStart = Len(txtReceived.Text)
  239.   txtReceived.SelText = "Connection to Server lost" & vbCrLf
  240. End Sub
  241. Private Sub wsMain_DataArrival(ByVal bytesTotal As Long)
  242.   Dim Data As String, CtrlChar As String
  243.   wsMain.GetData Data
  244.   CtrlChar = Left(Data, 1) ' Let's get the first char
  245.   Data = Mid(Data, 3)      ' Then cut it off
  246.   Select Case LCase(CtrlChar)   ' Check what it is
  247.     Case "m"   ' Do stuff depending on it
  248.       MsgBox Data, vbInformation, "Msg from server"
  249.     Case "c"
  250.       Me.Caption = "Client - " & Data
  251.     Case "r"
  252.       server_answer = Data
  253.       txtReceived.SelStart = Len(txtReceived.Text)
  254.       txtReceived.SelText = Data & vbCrLf
  255.     Case Else
  256.       txtReceived.SelStart = Len(txtReceived.Text)
  257.       txtReceived.SelText = Data & vbCrLf
  258.   End Select
  259. End Sub
  260. Private Sub wsMain_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
  261.   MsgBox "Winsock Error: " & Number & vbCrLf & Description, vbCritical, "Winsock Error"
  262. End Sub
  263. Private Function Senden(tex As String) As String
  264.   Dim antwort As String
  265.   Dim tax As String
  266.   On Error Resume Next
  267.   tax = tex
  268.   If tax = "" Then Exit Function
  269.   server_answer = ""
  270.   wsMain.SendData "r" & Chr(1) & tex
  271.   Timer1.Enabled = True
  272.   DoEvents
  273.   Do Until server_answer <> ""
  274.     DoEvents
  275.   Loop
  276.   If server_answer = "Time-Out" Then
  277.     MsgBox "Server Time Out!"
  278.   End If
  279.   Senden = server_answer
  280.   Exit Function
  281. errhand:
  282.   tex = Err.Description
  283.   'Errn = Err
  284.   'If Errn = 10048 Then
  285.   '  Resume
  286.   'Else
  287.     MsgBox tex, 16, "Fehler im WinSock"
  288.     Resume
  289.   'End If
  290. End Function
  291. Private Sub Timer1_Timer()
  292.   server_answer = "Server-Time out"
  293.   Timer1.Enabled = False
  294. End Sub
  295.