|
-
Jan 21st, 2006, 08:08 AM
#1
Thread Starter
Lively Member
Winsock SendData Problem
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;
VB 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!
-
Jan 21st, 2006, 12:14 PM
#2
New Member
Re: Winsock SendData Problem
first u need winsock1.connect , and than first send the data if winsock1.state = 7
-
Jan 21st, 2006, 02:33 PM
#3
Thread Starter
Lively Member
Re: Winsock SendData Problem
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
-
Jan 22nd, 2006, 02:27 PM
#4
Member
Re: Winsock SendData Problem
VB 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
[B]if Winsock1.State = 7 then[/B] 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
[B]if Winsock1.State = 7 then[/B] Winsock1.SendData "unban," + Text3.Text + "," + Text2.Text + "," + Text4.Text
MsgBox Text2.Text + " has been unbanned!"
End Sub
ss
-
Jan 22nd, 2006, 04:05 PM
#5
New Member
Re: Winsock SendData Problem
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
VB Code:
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
-
Jan 22nd, 2006, 05:00 PM
#6
Member
Re: Winsock SendData Problem
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
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
|