Results 1 to 17 of 17

Thread: Winsock.SendData problem with strings*unresolved*

  1. #1

    Thread Starter
    Addicted Member Booda's Avatar
    Join Date
    Aug 2001
    Location
    B.C, Canada
    Posts
    237

    Winsock.SendData problem with strings*unresolved*

    Hi all just a quick question:
    Can you send a string using senddata through a network

    VB Code:
    1. Private Sub Runner_Timer()
    2. Dim Sendoff As String
    3.  
    4.     Info = Time
    5.     lblInfo.Caption = Info
    6.     lblCompNam.Caption = ComputerNME
    7.     lblIP.Caption = IP
    8.     Sendoff = Info & "*" & ComputerNME & "*" & IP
    9.     Winsuck.SendData Sendoff
    10. End Sub

    I keep on getting a error "Wrong protocol or connection state for the requested transaction or state"
    I am using TCP, I know it works in UDP.
    anybody have any clues

    Thanks in advance
    Last edited by Booda; Oct 30th, 2002 at 07:39 PM.

  2. #2

    Thread Starter
    Addicted Member Booda's Avatar
    Join Date
    Aug 2001
    Location
    B.C, Canada
    Posts
    237
    is this such a bad question that no one would look at it even?

  3. #3
    Lively Member esmerelda's Avatar
    Join Date
    Sep 2002
    Location
    South Croydon, UK
    Posts
    68
    Hehehe.

    You have to set the type to AF_INET, the socket stream to SOCK_STREAM, and the protocol to IPPROTO_TCP. Then it'll work.

  4. #4

    Thread Starter
    Addicted Member Booda's Avatar
    Join Date
    Aug 2001
    Location
    B.C, Canada
    Posts
    237
    Wow !! I a bit a of a ......no i AM a newbie to winsock programming, where do you set the type, socket stream.
    As for the protocol I have 2 choices sckTCPProtocol and
    sckUDPProtocol

    Sorry bout that, I just have no clue yet

  5. #5
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    OK, this Might sound dumb, but have you created a connection yet?

    And u didnt close it or that (did u?)

    VB Code:
    1. ' If the Connection Socket on the MainClient is open, Close it
    2.     If frmMainClient.ConnSock(0).State <> sckClosed Then frmMainClient.ConnSock(0).Close
    3.    
    4.     ' Set the connection socket properties
    5.     frmMainClient.ConnSock(0).RemoteHost = Me.cboServerName.Text
    6.     frmMainClient.ConnSock(0).RemotePort = Me.cboPort.Text
    7.    
    8.     ' Connect to the server
    9.     frmMainClient.ConnSock(0).Connect
    10.    
    11.     ' Give the connection Four tries, and if it fails, tell the user
    12.     Do Until frmMainClient.ConnSock(0).State = sckConnected
    13.         DoEvents: DoEvents: DoEvents: DoEvents
    14.         If frmMainClient.ConnSock(0).State = sckError Then
    15.             MsgBox "There was a problem when trying to connect to the chat server!" _
    16.             & vbCrLf & "Either the server is down, or you aren't connected to the Internet", vbOKOnly, "Connection Error"
    17.             Exit Sub
    18.         End If
    19.     Loop
    20.    
    21.     frmMainClient.ConnSock(0).SendData (SendOff)


    Make the WinSock called "ConnSock" and an index of 0, if u dont plan on editing the code (You still need to edit the form name.

    frmMainClient = Form1, MyForm, ETC

    This should work?

    : Psst, be a little more descriptive with Titles Too .. Mite help people, cuz a lot of ppl only enter a thread if they *think* they will be able to A)Learn from it, or B)Help you

    Any how, see how that goes for u
    Wayne

  6. #6

    Thread Starter
    Addicted Member Booda's Avatar
    Join Date
    Aug 2001
    Location
    B.C, Canada
    Posts
    237
    yeah I did create the connection, i have done this before using sclUDPProtocol and it did work with a string, now that I'm using TCP, I seem to be having a problem
    Yes the connection has been made, i did close it before opening it, and the IP and port numbers are all in check

    Thanks for the responces and the extra help too

  7. #7
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    : OK, Well not exactly sure what it is then (I am a newbie [bout 1 / 2 weeks tops] working with WinSock Myself )
    Wayne

  8. #8

    Thread Starter
    Addicted Member Booda's Avatar
    Join Date
    Aug 2001
    Location
    B.C, Canada
    Posts
    237
    well thanks for the response anyways, this winsock thing seems to be a bit of an enigma to me.
    oh well tomorrow is another day

  9. #9
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    well... i don't think it's that code problem. show us your other code as well.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  10. #10

    Thread Starter
    Addicted Member Booda's Avatar
    Join Date
    Aug 2001
    Location
    B.C, Canada
    Posts
    237
    ok here is a list of the form:
    3 labels
    lblinfo
    lblcompnam
    lblip
    a command button called cmdSS
    a Timer called Runner
    winsock control call Winsuck (sorry just had to do it, and I'm sure I'm not the first)
    what I want this program to do is to just send out the system time of the computer, the name of the computer and the ip address.
    so heres the code:
    VB Code:
    1. 'CODE IN THE FORM
    2. Option Explicit
    3. Dim ComputerNME As String
    4. Dim Info As String
    5. Dim IP As String
    6. Dim TBuff() As Byte
    7.  
    8. Private Sub cmdSS_Click()
    9.     If cmdSS.Caption = "Start" Then
    10.         Runner.Enabled = True
    11.         cmdSS.Caption = "Stop"
    12.     Else
    13.         Runner.Enabled = False
    14.         cmdSS.Caption = "Start"
    15.     End If
    16.    
    17. End Sub
    18.  
    19. Private Sub Form_Load()
    20. Dim dwlen As Long
    21.  
    22.     cmdSS.Caption = "Start"
    23.     lblInfo.Caption = ""
    24.     lblCompNam.Caption = ""
    25.     lblIP.Caption = ""
    26.     dwlen = MAX_COMPUTERNAME_LENGTH + 1
    27.     ComputerNME = String(dwlen, "X")
    28.     GetComputerName ComputerNME, dwlen
    29.     ComputerNME = Left(ComputerNME, dwlen)
    30.     IP = Winsuck.LocalIP
    31.     Runner.Interval = 5000
    32.     Winsuck.Close
    33.     Winsuck.RemoteHost = "192.168.0.131"
    34.     Winsuck.RemotePort = 5150
    35.     Winsuck.Connect
    36.    
    37. End Sub
    38.  
    39. Private Sub Runner_Timer()
    40. Dim Sendoff As String
    41.  
    42.     Info = Time
    43.     lblInfo.Caption = Info
    44.     lblCompNam.Caption = ComputerNME
    45.     lblIP.Caption = IP
    46.     Sendoff = Info & "*" & ComputerNME & "*" & IP
    47.     Winsuck.SendData Sendoff
    48. End Sub
    49.  
    50.  
    51. 'CODE IN A MODULE
    52. Option Explicit
    53. Public Const MAX_COMPUTERNAME_LENGTH As Long = 51
    54. Declare Function GetComputerName Lib "KERNEL32" Alias "GetComputerNameA" _
    55.     (ByVal lpBuffer As String, nSize As Long) As Long
    56. Public Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, _
    57. ByVal cbCopy As Long)
    now the line that gives me the problem is:
    Winsuck.SendData Sendoff
    thanks for taking a look at this!!

  11. #11
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    Try:
    VB Code:
    1. Winsuck.SendData(Sendoff)
    Wayne

  12. #12

    Thread Starter
    Addicted Member Booda's Avatar
    Join Date
    Aug 2001
    Location
    B.C, Canada
    Posts
    237
    yeah I tried that and got the same error

  13. #13
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    :Wonders...

    Try and make a control array for the "Winsuck"

    Make the Index = (0)

    And change Winsuck. to Winsuck(0).

    Other then that, i can only think that, your server could be faulting?

    What is the error msg caused?
    Wayne

  14. #14
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    VB Code:
    1. 'CODE IN THE FORM
    2. Option Explicit
    3. Dim ComputerNME As String
    4. Dim Info As String
    5. Dim IP As String
    6. Dim TBuff() As Byte
    7.  
    8. Private Sub cmdSS_Click()
    9.     If cmdSS.Caption = "Start" Then
    10.         Runner.Enabled = True
    11.         cmdSS.Caption = "Stop"
    12.     Else
    13.         Runner.Enabled = False
    14.         cmdSS.Caption = "Start"
    15.     End If
    16.    
    17. End Sub
    18.  
    19. Private Sub Form_Load()
    20. Dim dwlen As Long
    21.  
    22.     cmdSS.Caption = "Start"
    23.     lblInfo.Caption = ""
    24.     lblCompNam.Caption = ""
    25.     lblIP.Caption = ""
    26.     dwlen = MAX_COMPUTERNAME_LENGTH + 1
    27.     ComputerNME = String(dwlen, "X")
    28.     GetComputerName ComputerNME, dwlen
    29.     ComputerNME = Left(ComputerNME, dwlen)
    30.     IP = Winsuck.LocalIP
    31.     Winsuck.Close
    32.     Winsuck.RemoteHost = "192.168.0.131"
    33.     Winsuck.RemotePort = 5150
    34.     Winsuck.Connect
    35.  
    36.     ' Give the connection Four tries, and if it fails, tell the user
    37.     Do Until Winsuck.State = sckConnected
    38.         DoEvents: DoEvents: DoEvents: DoEvents
    39.         If Winsuck.State = sckError Then
    40.             MsgBox "There was a problem when trying to connect to the server!" _
    41.             , vbOKOnly, "Connection Error"
    42.             Exit Sub
    43.         End If
    44.     Loop
    45.  
    46.     Runner.Interval = 5000
    47.     Runner.Enabled = False
    48. End Sub
    49.  
    50. Private Sub Runner_Timer()
    51. Dim Sendoff As String
    52.  
    53.     Info = Time
    54.     lblInfo.Caption = Info
    55.     lblCompNam.Caption = ComputerNME
    56.     lblIP.Caption = IP
    57.     Sendoff = Info & "*" & ComputerNME & "*" & IP
    58.     Winsuck.SendData Sendoff
    59. End Sub


    Check that.... Might work, might not (Worth a shot tho huh )
    Wayne

  15. #15

    Thread Starter
    Addicted Member Booda's Avatar
    Join Date
    Aug 2001
    Location
    B.C, Canada
    Posts
    237
    well I'll have to try that one when I get back into work tomorrow (currenly at home)
    I see what you did, and I do understand what you're getting at
    Thank you very much for the help, I will try this and try to reply on this thread again

  16. #16
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    : U Got VB At Home?
    : Prolly be able to "Blag" a copy off your work or that
    Wayne

  17. #17
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765
    Winsock1.Listen on the server

    and make sure you have the correct ip address and port set for computers. And maybe use a If Winsock1.state <> sckclosed....
    Don't Rate my posts.

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