|
-
Aug 13th, 2006, 05:38 PM
#1
Thread Starter
New Member
Programming MMO(Server Issues)
Hello guys, I'm new here so I don't know where I should post this (in networks or games)
Basically when the client connects to the server to send the chat message the server stops with the error type mismatch. I have tried everything I could think of to fix this and it didn't work.
I'm not sure if I should post the code of not but here goes.
Server Code
VB Code:
Private blnarray() As Boolean
Private Sub Command1_Click()
If Socket.Count <> 1 Then
For i = i To Socket.Count - 1
Socket(i).Close
Next i
Else
status = "Server Stopped!"
End If
End Sub
Private Sub Command2_Click()
If Socket.Count <> 1 Then
For i = 1 To Socket.Count - 1
If blnarray(i) = False Then 'Checks if the socket at index "i" is available
Socket(i).Close
Exit Sub
End If
Next i
End If
Unload All
End Sub
Private Sub Form_Load()
ReDim blnarray(0)
Socket(0).LocalPort = "22101"
Socket(0).Listen
blnarray(0) = True
End Sub
Private Sub Form_Terminate()
Close
End Sub
Private Sub Form_Unload(Cancel As Integer)
Close
End Sub
Private Sub Socket_ConnectionRequest(Index As Integer, ByVal requestID As Long)
'Check if any free sockets
If Socket.Count <> 1 Then
For i = 1 To Socket.Count - 1
If blnarray(i) = False Then 'Checks if the socket at index "i" is available
Socket(i).Accept requestID 'Accepted connection to old but available socket
Exit Sub
End If
Next i
End If
'Only runs if no open sockets
'Increase size of blnArray
ReDim Preserve blnarray(Socket.UBound + 1)
'Load new Winsock1
Load Socket(Socket.UBound + 1)
'Accept Connection to newly created socket
Socket(Socket.UBound).Accept requestID
'Updates the Array at requested position to true stating socket is in use at theis index
blnarray(Socket.UBound) = True
'Do not worry your new Winsock1 control automatically is given an open port by the Windows OS
End Sub
Private Sub Socket_DataArrival(Index As Integer, ByVal bytesTotal As Long)
status = "Receiving Data!"
ReDim dat(5)
Dim dat_a As String
Call Socket(Index).GetData(dat_a, vbString)
dat = Split(dat_a, ",")
status = "Data Received!"
If inarray("chat", dat) = True Then
Dim dat1 As String
dat1 = "chat," + dat(3) + "," + dat(2) + "," + dat(4)
If Socket.Count <> 1 Then
For i = 1 To Socket.Count - 1
If blnarray(i) = False Then
Socket(i).SendData (dat1)
Exit Sub
End If
Next i
End If
Else
Socket(Index).SendData "Error! You are not using the game client to access this server and port. Your IP has been logged and sent to our anti hacking group!"
'Dim dat1 As String
'dat1 = "chat," + dat(3) + "," + dat(2) + "," + dat(4)
'Socket(Index).SendData dat1
End If
End Sub
Private Sub Socket_SendComplete(Index As Integer)
status = "Pending New Connection. . ."
Socket(Index).Close
End Sub
Private Sub Socket_SendProgress(Index As Integer, ByVal bytesSent As Long, ByVal bytesRemaining As Long)
status = "Sending Data!"
End Sub
Public Function inarray(expression As String, a As Variant) As Boolean
Dim fval As Boolean
x = 4
If x <> 1 Then
For i = 1 To x = -1
If a(i) = expression Then
inarray = True
End If
Next i
End If
End Function
And heres the client code
VB Code:
'Private dat1_a() As String
Private connected As Boolean
Private Sub chatsubmit_Click()
'dat = "chat," + chattype.Text + "," + to_c.Text + "," + chattxt.Text
dat = Array("chat", chattype.Text, to_c.Text, chattxt.Text)
Dim dat_a As String
dat_a = Join(dat, ",")
If connected = True Then
sock.SendData (dat_a)
ElseIf connected = False Then
If sock.State = 8 Then
sock.Close
While sock.State <> sckClosed
Wend
sock.Connect
Else
'sock.Connect
End If
End If
End Sub
Private Sub conn_Timer()
If connected = False Then
sock.Close
While sock.State <> sckClosed
Wend
sock.Connect
Else
Exit Sub
End If
End Sub
Private Sub Form_Load()
'text As String
text_v = "[System] Welcome to the example of the chat system."
chatview = chatview + vbCrLf + text_v
sock.RemoteHost = "localhost"
sock.RemotePort = "22101"
sock.Connect
End Sub
Private Sub sock_Close()
connected = False
End Sub
Private Sub sock_Connect()
connected = True
End Sub
Private Sub sock_DataArrival(ByVal bytesTotal As Long)
Dim dat_a1() As String
Dim dat1 As String
Call sock.GetData(dat1)
dat_a1 = Split(dat1, ",")
Dim dat1_a(0 To 4) As String
count1 = 4
'If count1 <> 1 Then
' For i = 1 To count1 - 1
' dat1_a(i) = dat_a1(i)
' Next i
'End If
MsgBox (dat1)
If dat1_a(0) = "GM" Then
gmview = "[GM] " + dat1_a(3)
ElseIf dat1_a(0) = "System" Then
chatview = "[System] " + dat1_a(3)
Else
chatview.Caption = dat1
End If
End Sub
Private Sub sock_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)
m = MsgBox("Error. Disconnected from the server and cannot reconnect.", vbOKOnly, "Error with connection!")
Unload Form1
Unload Form2
Close
End Sub
Private Sub Timer1_Timer()
gmview = ""
Timer1.Enabled = False
End Sub
I'm only trying to get the chat to work so I can test and make sure that my Winsock multi connection works then I will begin developing movements of such.
I know the code is very ugly but I'm not a VB6 Programmer lol, I program in PHP.
All help greatly appreciated.
Thanks guys.
Last edited by dreiecon; Aug 13th, 2006 at 05:54 PM.
[VBCODE]
Private Sub form1_load()
If programming = fun then
MsgBox ("Programming is so much fun!")
Else
MsgBox ("Learn to program n00b")
End If
End Sub[/VBCODE]
-
Aug 17th, 2006, 07:29 AM
#2
Thread Starter
New Member
Re: Programming MMO(Server Issues)
[VBCODE]
Private Sub form1_load()
If programming = fun then
MsgBox ("Programming is so much fun!")
Else
MsgBox ("Learn to program n00b")
End If
End Sub[/VBCODE]
-
Aug 17th, 2006, 08:56 AM
#3
Re: Programming MMO(Server Issues)
"Type Mismatch" means that you are not using data types properly - for example, you may be trying to put a string value into an Integer variable/property.
Which line is the error occuring on?
-
Aug 17th, 2006, 04:26 PM
#4
Thread Starter
New Member
Re: Programming MMO(Server Issues)
This entire area is not working correctly.
VB Code:
Private Sub Socket_DataArrival(Index As Integer, ByVal bytesTotal As Long)
status = "Receiving Data!"
ReDim dat(5)
Dim dat_a As String
Call Socket(Index).GetData(dat_a, vbString)
dat = Split(dat_a, ",")
status = "Data Received!"
If inarray("chat", dat) = True Then
Dim dat1 As String
dat1 = "chat," + dat(3) + "," + dat(2) + "," + dat(4)
If Socket.Count <> 1 Then
For i = 1 To Socket.Count - 1
If blnarray(i) = False Then
Socket(i).SendData (dat1)
Exit Sub
End If
Next i
End If
Else
Socket(Index).SendData "Error! You are not using the game client to access this server and port. Your IP has been logged and sent to our anti hacking group!"
'Dim dat1 As String
'dat1 = "chat," + dat(3) + "," + dat(2) + "," + dat(4)
'Socket(Index).SendData dat1
End If
End Sub
[VBCODE]
Private Sub form1_load()
If programming = fun then
MsgBox ("Programming is so much fun!")
Else
MsgBox ("Learn to program n00b")
End If
End Sub[/VBCODE]
-
Aug 17th, 2006, 05:23 PM
#5
Re: Programming MMO(Server Issues)
There's nothing obvious, but we can probably work it out if you tell us which line the error is occuring on.
-
Aug 18th, 2006, 05:19 AM
#6
Thread Starter
New Member
Re: Programming MMO(Server Issues)
Ok. I've fixed it as much as I can.
I now use;
VB Code:
Dim dat() as String
dat = Split(dat_a)
I try to call the array value "dat(0)" and I get;
"Run-time error '9':
Subscript out of range"
It then highlights the line that uses the array value "dat(0)".
[VBCODE]
Private Sub form1_load()
If programming = fun then
MsgBox ("Programming is so much fun!")
Else
MsgBox ("Learn to program n00b")
End If
End Sub[/VBCODE]
-
Aug 18th, 2006, 10:19 AM
#7
Re: Programming MMO(Server Issues)
That would be beacuse dat_a is empty (so Split doesnt have anything to return).
You need to check that dat_a contains something before you Split it.
-
Aug 18th, 2006, 09:31 PM
#8
Thread Starter
New Member
Re: Programming MMO(Server Issues)
dat_a is set by;
"Call Socket(Index).GetData(dat_a)"
[VBCODE]
Private Sub form1_load()
If programming = fun then
MsgBox ("Programming is so much fun!")
Else
MsgBox ("Learn to program n00b")
End If
End Sub[/VBCODE]
-
Aug 19th, 2006, 09:49 AM
#9
Re: Programming MMO(Server Issues)
That's what I assumed, but it doesnt change the fact that dat_a is empty when the error occurs.
If you provide any text to Split, it will return an array with at least one value - so dat(0) will be valid if text has been provided.
-
Aug 19th, 2006, 05:46 PM
#10
Thread Starter
New Member
Re: Programming MMO(Server Issues)
Thanks for your help.
I've managed to fix this =D
What the problem was is, I received the data sent by the client as "??????????" so I added "Dim dat_a as String" and it worked with a bit of tweaking.
Thanks so much for your help.
[VBCODE]
Private Sub form1_load()
If programming = fun then
MsgBox ("Programming is so much fun!")
Else
MsgBox ("Learn to program n00b")
End If
End Sub[/VBCODE]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|