PDA

Click to See Complete Forum and Search --> : Winsock SendData Problem


UrlGuy
Jan 21st, 2006, 07:08 AM
Hi,

I have a simple program on a remote server listening for connections on TCP port 1980.
This is for gameserver management.

When it recieves for example 'ban,ip,username,reason' on port 1980, it will ban that player.

I'm trying to make a app in Winsock so I can ban players from my desktop..
What I have now is the following code;


Private Sub Command1_Click()
If Text1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Or Text4.Text = "" Then MsgBox "You didnt fill out all fields", vbCritical, "Error!"
Winsock1.RemoteHost = Text1.Text
Winsock1.RemotePort = 1980
Winsock1.SendData "ban," + Text2.Text + "," + Text2.Text + "," + Text4.Text
MsgBox Text3.Text + " has been banned!"
End Sub

Private Sub Command2_Click()
If Text1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Or Text4.Text = "" Then MsgBox "You didnt fill out all fields", vbCritical, "Error!"
Winsock1.RemoteHost = Text1.Text
Winsock1.RemotePort = 1980
Winsock1.SendData "unban," + Text3.Text + "," + Text2.Text + "," + Text4.Text
MsgBox Text2.Text + " has been unbanned!"
End Sub


But when I click one of my buttons I get something like "Wrong protocol or connection state.."

Can anyone help me with this?

Thanks in advance!

dddmaster
Jan 21st, 2006, 11:14 AM
first u need winsock1.connect , and than first send the data if winsock1.state = 7

UrlGuy
Jan 21st, 2006, 01:33 PM
Hi,

Thanks for your reply!

Could you please tell me where in my code I need to put Winsock1.connect ?

Thanks in advance!

Best Regards,
~url

dlern
Jan 22nd, 2006, 01:27 PM
Private Sub Command1_Click()
If Text1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Or Text4.Text = "" Then MsgBox "You didnt fill out all fields", vbCritical, "Error!"
Winsock1.RemoteHost = Text1.Text
Winsock1.RemotePort = 1980
if Winsock1.State = 7 then Winsock1.SendData "ban," + Text2.Text + "," + Text2.Text + "," + Text4.Text
MsgBox Text3.Text + " has been banned!"
End Sub

Private Sub Command2_Click()
If Text1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Or Text4.Text = "" Then MsgBox "You didnt fill out all fields", vbCritical, "Error!"
Winsock1.RemoteHost = Text1.Text
Winsock1.RemotePort = 1980
if Winsock1.State = 7 then Winsock1.SendData "unban," + Text3.Text + "," + Text2.Text + "," + Text4.Text
MsgBox Text2.Text + " has been unbanned!"
End Sub
ss

dddmaster
Jan 22nd, 2006, 03:05 PM
hm.. not very well... try this , sry with the timer1 code xD
First create a third button with caption connect then a timer with interval 1

Private Sub Command3_Click()
if winsock1.state = 0 then
winsock1.RemoteHost
Winsock1.RemoteHost = Text1.Text
Winsock1.RemotePort = 1980
endif
End Sub

Private Sub Command1_Click()
If Text1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Or Text4.Text = "" Then MsgBox "You didnt fill out all fields", vbCritical, "Error!"
if winsock1.state = 7 then
Winsock1.SendData "ban," + Text2.Text + "," + Text2.Text + "," + Text4.Text
MsgBox Text3.Text + " has been banned!"
else
MsgBox "Press the connect button first"
endif
End Sub

Private Sub Command2_Click()
If Text1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Or Text4.Text = "" Then MsgBox "You didnt fill out all fields", vbCritical, "Error!"
if winsock1.state = 7 then
Winsock1.SendData "unban," + Text3.Text + "," + Text2.Text + "," + Text4.Text
MsgBox Text2.Text + " has been unbanned!"
else
MsgBox "Press the connect button first"
endif
End Sub

Private Sub Timer1_dont know atm sry xD()
if winsock1.state = 8 then
MsgBox "you have been disconnected"
winsock1.close
endif
if winsock1.state = 9 then
MsgBox "Connection could not been established , check the ip and ur network connection!"
winsock1.close
endif
end sub

dlern
Jan 22nd, 2006, 04:00 PM
there is a a lot more to winsock (as I am learning) than just sending data. I just indicated where the connection state test would be placed (as was aksed). But there is much more about his gameserver management that is not indicated. Is this a multiclient server, what is the criteria for banning? if mulitclient, are you sending ban commnad to proper client?

take a look at these to get a handle on winsock server mutilclient programming

http://www.winsockvb.com/article.php?article_id=18
http://www.winsockvb.com/article.php?article_id=19