Find all our projects in development below.
All source code is GNU General Public License (GPL)
Browsing TicTacConn.frm (13.14 KB)
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.Form TicTacToeConnForm
BorderStyle = 3 'Fixed Dialog
Caption = "Join/Host TCP/IP Tic Tac Toe Game"
ClientHeight = 2670
ClientLeft = 45
ClientTop = 330
ClientWidth = 6255
ClipControls = 0 'False
Icon = "TicTacConn.frx":0000
LinkTopic = "TicTacToeConnForm"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 2670
ScaleWidth = 6255
ShowInTaskbar = 0 'False
StartUpPosition = 2 'CenterScreen
Begin VB.CommandButton Command3
Caption = "Cancel"
Default = -1 'True
Height = 375
Left = 2400
TabIndex = 6
Top = 2160
Width = 1455
End
Begin VB.Frame Frame2
Caption = "Host Game"
Height = 1815
Left = 3240
TabIndex = 10
Top = 120
Width = 2895
Begin VB.CommandButton Command1
Caption = "&Host Game"
Height = 375
Left = 1200
TabIndex = 5
Top = 1200
Width = 1455
End
Begin VB.TextBox Text4
Alignment = 2 'Center
Height = 285
Left = 1200
MaxLength = 4
TabIndex = 4
Text = "8660"
Top = 720
Width = 1455
End
Begin VB.TextBox Text1
Alignment = 2 'Center
Height = 285
Left = 1200
Locked = -1 'True
TabIndex = 3
Top = 360
Width = 1455
End
Begin VB.Label Label4
Caption = "Port:"
Height = 255
Left = 760
TabIndex = 12
Top = 750
Width = 375
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "Host Address:"
Height = 195
Left = 120
TabIndex = 11
Top = 390
Width = 990
End
End
Begin VB.Frame Frame1
Caption = "Join Game"
Height = 1815
Left = 120
TabIndex = 7
Top = 120
Width = 2895
Begin VB.CommandButton Command2
Caption = "&Join Game"
Height = 375
Left = 1200
TabIndex = 2
Top = 1200
Width = 1455
End
Begin VB.TextBox Text2
Alignment = 2 'Center
Height = 285
Left = 1200
MaxLength = 16
TabIndex = 0
Text = "0.0.0.0"
Top = 330
Width = 1455
End
Begin VB.TextBox Text3
Alignment = 2 'Center
Height = 285
Left = 1200
MaxLength = 4
TabIndex = 1
Text = "8660"
Top = 720
Width = 1455
End
Begin VB.Label Label1
Caption = "Remote Host:"
Height = 255
Left = 120
TabIndex = 9
Top = 360
Width = 1215
End
Begin VB.Label Label2
Caption = "Port:"
Height = 255
Left = 760
TabIndex = 8
Top = 750
Width = 375
End
End
Begin MSWinsockLib.Winsock Winsock1
Left = 120
Top = 2040
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
End
Attribute VB_Name = "TicTacToeConnForm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim MsgColors()
Dim NoClose, NoClose2
Private Sub Command3_Click()
Unload Me
End Sub
Private Sub Form_Load()
Text1.Text = Winsock1.LocalIP
ReDim MsgColors(6)
MsgColors(0) = vbBlack
MsgColors(1) = vbRed
MsgColors(2) = vbYellow
MsgColors(3) = vbGreen
MsgColors(4) = vbBlue
MsgColors(5) = vbCyan
MsgColors(6) = vbMagenta
NoClose = False
NoClose2 = False
End Sub
Sub SendCmd(Cmd As String)
Winsock1.SendData Cmd
End Sub
Private Sub Command2_Click()
On Error GoTo FixErr
Command1.Enabled = False
Command2.Enabled = False
Winsock1.Close
Caption = "Join/Host TCP/IP Tic Tac Toe Game - Connecting..."
Winsock1.Connect Text2.Text, Text3.Text
Exit Sub
FixErr:
Winsock1.Close
Command1.Enabled = True
Command2.Enabled = True
Caption = "Join/Host TCP/IP Tic Tac Toe Game"
MsgBox "Error: " + Err.Description, vbOKOnly + vbExclamation
End Sub
Private Sub Command1_Click()
On Error GoTo FixErr
If Command1.Caption = "&Host Game" Then
Command2.Enabled = False
Command1.Caption = "Stop &Listening"
Caption = "Join/Host TCP/IP Tic Tac Toe Game - Listening..."
Winsock1.Close
Winsock1.LocalPort = Text4.Text
Winsock1.Listen
Exit Sub
End If
If Command1.Caption = "Stop &Listening" Then
Command2.Enabled = True
Caption = "Join/Host TCP/IP Tic Tac Toe Game"
Winsock1.Close
Command1.Caption = "&Host Game"
End If
Exit Sub
FixErr:
Winsock1.Close
Command1.Caption = "&Host Game"
Command2.Enabled = True
Caption = "Join/Host TCP/IP Tic Tac Toe Game"
MsgBox "Error: " + Err.Description, vbOKOnly + vbExclamation
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Winsock1.Close
End Sub
Private Sub Text1_GotFocus()
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End Sub
Private Sub Text2_Click()
Command1.Default = Command1.Enabled
End Sub
Private Sub Text2_Change()
If Text2.Text = "" Then Command2.Enabled = False
If Text2.Text <> "" And Text3.Text <> "" Then Command2.Enabled = True
End Sub
Private Sub Text2_GotFocus()
Text2.SelStart = 0
Text2.SelLength = Len(Text2.Text)
End Sub
Private Sub Text3_Change()
If Text3.Text = "" Then Command2.Enabled = False
If Text2.Text <> "" And Text3.Text <> "" Then Command2.Enabled = True
End Sub
Private Sub Text3_GotFocus()
Text3.SelStart = 0
Text3.SelLength = Len(Text3.Text)
End Sub
Private Sub Text3_KeyPress(KeyAscii As Integer)
If KeyAscii >= 48 And KeyAscii <= 57 Or KeyAscii = 8 Then Exit Sub
KeyAscii = 0
End Sub
Private Sub Text4_Change()
If Text4.Text = "" Then Command1.Enabled = False
If Text4.Text <> "" Then Command1.Enabled = True
End Sub
Private Sub Text4_GotFocus()
Text4.SelStart = 0
Text4.SelLength = Len(Text4.Text)
End Sub
Private Sub Text4_KeyPress(KeyAscii As Integer)
If KeyAscii >= 48 And KeyAscii <= 57 Or KeyAscii = 8 Then Exit Sub
KeyAscii = 0
End Sub
Private Sub Winsock1_Close()
On Error Resume Next
Winsock1.Close
If NoClose = True Then
Caption = "Join/Host TCP/IP Tic Tac Toe Game"
Command1.Enabled = True
Command2.Enabled = True
Command1.Caption = "&Host Game"
MsgBox "Error: Version Numbers Do Not Match!", vbOKOnly + vbCritical
NoClose = False
Exit Sub
End If
If NoClose2 = False Then MsgBox "Connection Closed By Remote Computer.", vbOKOnly + vbExclamation
Unload TicTacToeMultiForm
Unload Me
End Sub
Private Sub Winsock1_Connect()
Caption = "Join/Host TCP/IP Tic Tac Toe Game - Connected, Please Wait..."
Command1.Enabled = False
Command2.Enabled = False
TCPIPName = "Client"
ClientIP = Winsock1.LocalIP
HostIP = Winsock1.RemoteHostIP
SendCmd "connect_ready:" & Winsock1.LocalIP & vbTab & App.Major & "." & App.Minor & "." & App.Revision
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
On Error Resume Next
Unload TicTacToeMultiForm
Winsock1.Close
Winsock1.Accept requestID
Caption = "Join/Host TCP/IP Tic Tac Toe Game - Connected, Please Wait..."
Command1.Enabled = False
Command2.Enabled = False
TCPIPName = "Host"
Command1.Caption = "&Host Game"
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim RecData As String
Dim MainHeader
On Error GoTo FixErr
Winsock1.GetData RecData
C1 = InStr(RecData, ":")
MainHeader = Left(RecData, C1 - 1)
If MainHeader <> "ch_msg" And _
MainHeader <> "connect_ready" And _
MainHeader <> "connect_ready_rec" And _
MainHeader <> "ch_send_beep" And _
MainHeader <> "player_move" And _
MainHeader <> "new_game" And _
MainHeader <> "ch_internal_msg" Then
MsgBox "Invalid Data Received!", vbOKOnly + vbExclamation
Exit Sub
End If
If MainHeader = "ch_internal_msg" Then
TicTacToeMultiForm.RichTextBox1.SelStart = Len(TicTacToeMultiForm.RichTextBox1.Text)
TicTacToeMultiForm.RichTextBox1.SelColor = vbMagenta
TicTacToeMultiForm.RichTextBox1.SelText = "Remote Computer Msg: "
TicTacToeMultiForm.RichTextBox1.SelStart = Len(TicTacToeMultiForm.RichTextBox1.Text)
TicTacToeMultiForm.RichTextBox1.SelColor = vbBlack
TicTacToeMultiForm.RichTextBox1.SelText = Mid(RecData, C1 + 1) & vbCrLf
If RecData = "ch_internal_msg:Error: Version Numbers Do Not Match!" Then Winsock1_Close
Exit Sub
End If
If MainHeader = "connect_ready" Then
C2 = InStr(C1 + 1, RecData, vbTab)
N = 0
V1 = App.Major & "." & App.Minor & "." & App.Revision
V2 = Mid(RecData, C2 + 1)
If V1 <> V2 Then N = 1: NoClose = True
SendCmd "connect_ready_rec:" & N
If N = 1 Then Exit Sub
ClientIP = Mid(RecData, C1 + 1, C2 - C1 - 1)
HostIP = Winsock1.LocalIP
Me.Hide
TicTacToeMultiForm.Caption = "TCP/IP Tic Tac Toe Game (Host) - Joined By " + ClientIP
TicTacToeMultiForm.Show 1
Exit Sub
End If
If MainHeader = "connect_ready_rec" Then
If Mid(RecData, C1 + 1) = "1" Then
Winsock1.Close
Caption = "Join/Host TCP/IP Tic Tac Toe Game"
Command1.Enabled = True
Command2.Enabled = True
Command1.Caption = "&Host Game"
MsgBox "Error: Version Numbers Do Not Match!", vbOKOnly + vbCritical
Exit Sub
End If
TicTacToeMultiForm.Caption = "TCP/IP Tic Tac Toe Game (Client) - Hosted By " + Winsock1.RemoteHost
Me.Hide
TicTacToeMultiForm.Show 1
Exit Sub
End If
If MainHeader = "player_move" Then
Dim Index As Integer
Index = Val(Mid(RecData, C1 + 1))
If TCPIPName = "Client" Then Board(Index) = PLAYER_HOST: NextPlayer = PLAYER_CLIENT
If TCPIPName = "Host" Then Board(Index) = PLAYER_CLIENT: NextPlayer = PLAYER_HOST
TicTacToeMultiForm.DrawSquare Index
If TicTacToeMultiForm.GameOver() Then Exit Sub
TicTacToeMultiForm.PlayerHasMoved
Exit Sub
End If
If MainHeader = "new_game" Then
TicTacToeMultiForm.RichTextBox1.SelStart = Len(TicTacToeMultiForm.RichTextBox1.Text)
TicTacToeMultiForm.RichTextBox1.SelColor = vbMagenta
TicTacToeMultiForm.RichTextBox1.SelText = "Host: "
TicTacToeMultiForm.RichTextBox1.SelStart = Len(TicTacToeMultiForm.RichTextBox1.Text)
TicTacToeMultiForm.RichTextBox1.SelColor = vbBlack
TicTacToeMultiForm.RichTextBox1.SelText = "New Game Started." & vbCrLf
TicTacToeMultiForm.StartNewGame
Exit Sub
End If
C2 = InStr(C1 + 1, RecData, ":")
If MainHeader = "ch_send_beep" Then
TicTacToeMultiForm.RichTextBox1.SelStart = Len(TicTacToeMultiForm.RichTextBox1.Text)
TicTacToeMultiForm.RichTextBox1.SelColor = vbRed
TicTacToeMultiForm.RichTextBox1.SelText = Mid(RecData, C2 + 1) + ": "
TicTacToeMultiForm.RichTextBox1.SelStart = Len(TicTacToeMultiForm.RichTextBox1.Text)
TicTacToeMultiForm.RichTextBox1.SelColor = MsgColors(Val(Mid(RecData, C1 + 1, C2 - C1 - 1)))
TicTacToeMultiForm.RichTextBox1.SelText = "Beep!" & vbCrLf
Beep
Exit Sub
End If
C3 = InStr(C2 + 1, RecData, vbTab)
Cl = Val(Mid(RecData, C1 + 1, C2 - C1 - 1))
NN = Mid(RecData, C2 + 1, C3 - C2 - 1)
Msg = Mid(RecData, C3 + 1)
TicTacToeMultiForm.RichTextBox1.SelStart = Len(TicTacToeMultiForm.RichTextBox1.Text)
TicTacToeMultiForm.RichTextBox1.SelColor = vbRed
TicTacToeMultiForm.RichTextBox1.SelText = NN + ": "
TicTacToeMultiForm.RichTextBox1.SelStart = Len(TicTacToeMultiForm.RichTextBox1.Text)
TicTacToeMultiForm.RichTextBox1.SelColor = MsgColors(Cl)
TicTacToeMultiForm.RichTextBox1.SelText = Msg & vbCrLf
Exit Sub
FixErr:
MsgBox "Error: " + Err.Description, vbOKOnly + vbExclamation
NoClose2 = True
Winsock1_Close
End Sub
Private Sub Winsock1_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)
If Number = 10054 Then
Winsock1_Close
Exit Sub
End If
If Number = 10061 Then
MsgBox "Error: Invalid Host or Wrong Port!", vbOKOnly + vbExclamation
Caption = "Join/Host TCP/IP Tic Tac Toe Game"
Command1.Enabled = True
Command2.Enabled = True
Command1.Caption = "&Host Game"
Exit Sub
Else
MsgBox "Error: " + Description, vbOKOnly + vbExclamation
End If
Winsock1.Close
Unload TicTacToeMultiForm
Unload Me
End Sub