Results 1 to 6 of 6

Thread: Winsock SendData Problem

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Location
    Norway
    Posts
    71

    Unhappy 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:
    1. Private Sub Command1_Click()
    2. If Text1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Or Text4.Text = "" Then MsgBox "You didnt fill out all fields", vbCritical, "Error!"
    3. Winsock1.RemoteHost = Text1.Text
    4. Winsock1.RemotePort = 1980
    5. Winsock1.SendData "ban," + Text2.Text + "," + Text2.Text + "," + Text4.Text
    6. MsgBox Text3.Text + " has been banned!"
    7. End Sub
    8.  
    9. Private Sub Command2_Click()
    10. If Text1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Or Text4.Text = "" Then MsgBox "You didnt fill out all fields", vbCritical, "Error!"
    11. Winsock1.RemoteHost = Text1.Text
    12. Winsock1.RemotePort = 1980
    13. Winsock1.SendData "unban," + Text3.Text + "," + Text2.Text + "," + Text4.Text
    14. MsgBox Text2.Text + " has been unbanned!"
    15. 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!

  2. #2
    New Member
    Join Date
    Jan 2006
    Posts
    11

    Re: Winsock SendData Problem

    first u need winsock1.connect , and than first send the data if winsock1.state = 7

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Location
    Norway
    Posts
    71

    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

  4. #4
    Member
    Join Date
    Jan 2006
    Posts
    40

    Re: Winsock SendData Problem

    VB Code:
    1. Private Sub Command1_Click()
    2. If Text1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Or Text4.Text = "" Then MsgBox "You didnt fill out all fields", vbCritical, "Error!"
    3. Winsock1.RemoteHost = Text1.Text
    4. Winsock1.RemotePort = 1980
    5. [B]if  Winsock1.State = 7 then[/B] Winsock1.SendData "ban," + Text2.Text + "," + Text2.Text + "," + Text4.Text
    6. MsgBox Text3.Text + " has been banned!"
    7. End Sub
    8.  
    9. Private Sub Command2_Click()
    10. If Text1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Or Text4.Text = "" Then MsgBox "You didnt fill out all fields", vbCritical, "Error!"
    11. Winsock1.RemoteHost = Text1.Text
    12. Winsock1.RemotePort = 1980
    13. [B]if  Winsock1.State = 7 then[/B] Winsock1.SendData "unban," + Text3.Text + "," + Text2.Text + "," + Text4.Text
    14. MsgBox Text2.Text + " has been unbanned!"
    15. End Sub
    16. ss

  5. #5
    New Member
    Join Date
    Jan 2006
    Posts
    11

    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:
    1. Private Sub Command3_Click()
    2. if winsock1.state = 0 then
    3. winsock1.RemoteHost
    4. Winsock1.RemoteHost = Text1.Text
    5. Winsock1.RemotePort = 1980
    6. endif
    7. End Sub
    8.  
    9. Private Sub Command1_Click()
    10. If Text1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Or Text4.Text = "" Then MsgBox "You didnt fill out all fields", vbCritical, "Error!"
    11. if winsock1.state = 7 then
    12. Winsock1.SendData "ban," + Text2.Text + "," + Text2.Text + "," + Text4.Text
    13. MsgBox Text3.Text + " has been banned!"
    14. else
    15. MsgBox "Press the connect button first"
    16. endif
    17. End Sub
    18.  
    19. Private Sub Command2_Click()
    20. If Text1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Or Text4.Text = "" Then MsgBox "You didnt fill out all fields", vbCritical, "Error!"
    21. if winsock1.state = 7 then
    22. Winsock1.SendData "unban," + Text3.Text + "," + Text2.Text + "," + Text4.Text
    23. MsgBox Text2.Text + " has been unbanned!"
    24. else
    25. MsgBox "Press the connect button first"
    26. endif
    27. End Sub
    28.  
    29. Private Sub Timer1_dont know atm sry xD()
    30. if winsock1.state = 8 then
    31. MsgBox "you have been disconnected"
    32. winsock1.close
    33. endif
    34. if winsock1.state = 9 then
    35. MsgBox "Connection could not been established , check the ip and ur network connection!"
    36. winsock1.close
    37. endif
    38. end sub

  6. #6
    Member
    Join Date
    Jan 2006
    Posts
    40

    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
  •  



Click Here to Expand Forum to Full Width