Results 1 to 9 of 9

Thread: Help With Winsock ( Send Packet )

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2007
    Posts
    5

    Help With Winsock ( Send Packet )

    Spanish / English

    Buenas noches, necesito crear un programa en Visual Basic que haga lo siguiente:

    Al tocar la tecla "X" se envie el paquete de informacion ( 05 0E por ejemplo ) a tal direcion de ip mediante tal socket ...

    Tengo el ip, tengo el socket, tengo el paquete, me faltaria solo saber como enviarlo, alguna solucion? ...

    ****************************
    ****************************

    Good night, I need to create a program in Visual Basic that does the following thing:

    When touching the key "X" send the packet of information (05 0E for example) to so address of IP by means of so socket ...

    I have the IP, I have socket, I have the package, but not like sending it, some solution? ...

    Notes:
    Ip: 127.0.0.1 ( for example )
    Socket: 1000
    Port: 7500
    Packet: 05 0E

    Edit:

    Code:
    Private Sub Command1_Click()
    
    Dim myArr(1) As Byte
    myArr(0) = 5
    myArr(1) = 0
    
    Winsock1.RemoteHost = "xxx.xxx.xxx.xxx"
    Winsock1.RemotePort = xxxx
    Winsock1.LocalPort = "xxxx"
    Winsock1.SendData myArr
    
    End Sub
    Error:



    Last edited by Jorgitoh; Sep 22nd, 2007 at 04:24 AM.

  2. #2

    Thread Starter
    New Member
    Join Date
    Sep 2007
    Posts
    5

    Re: Help With Winsock ( Send Packet )

    Edited ...

    Last edited by Jorgitoh; Sep 22nd, 2007 at 05:09 AM. Reason: Duplicate Post

  3. #3
    Fanatic Member drivenbywhat's Avatar
    Join Date
    Jan 2007
    Location
    VA - USA
    Posts
    866

    Re: Help With Winsock ( Send Packet )

    first, before using any winsock code, put:

    winsock.close

    then make sure you put the acutal index of the array you want to send.

    winsock.senddata myarr(x)
    'substitute x with the array index

    You are also going to need to have an application listening on the port you are sending the data to. If you already have this then don't worry. If you want to know more about winsock, go to the NETWORKING section of the forums. There's a lot of frequently asked questions there.
    Last edited by drivenbywhat; Sep 22nd, 2007 at 10:30 AM.
    [vb5 & starting to move to vb2008] I appreciate the help I get from everyone. Thank you.

  4. #4

    Thread Starter
    New Member
    Join Date
    Sep 2007
    Posts
    5

    Re: Help With Winsock ( Send Packet )

    I want to send all those together bytes in chain form, for that reason I do not put the (x) next to myarr...

    I already have a game running in that IP and that port (remote host & port), therefore the connection already this established, anyway to me continues appearing the error...


  5. #5
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Help With Winsock ( Send Packet )

    even if you want to send all the values use a loop to loop thru your array and then send it...
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  6. #6
    Fanatic Member drivenbywhat's Avatar
    Join Date
    Jan 2007
    Location
    VA - USA
    Posts
    866

    Re: Help With Winsock ( Send Packet )

    Did you put the "winsock.close" like I told you? Your error is saying it is in the wrong state for what you are trying to do. This means that either you are "listening" somewhere and shouldn't be because you are trying to connect. It could also mean that winsock isn't even connecting. Try the following code:

    vb Code:
    1. Dim myArr(1) As Byte
    2. myArr(0) = 5
    3. myArr(1) = 0
    4.  
    5. winsock1.close
    6. Winsock1.RemoteHost = "xxx.xxx.xxx.xxx"
    7. Winsock1.RemotePort = xxxx
    8. 'you need this so you can connect before trying to send anything!
    9. winsock1.connect
    10. 'no need for local port, it already knows this itself
    11. 'Winsock1.LocalPort = "xxxx"
    12.  
    13. 'make sure to declare x
    14. for x = 0 to 1
    15. Winsock1.SendData myArr(x)
    16. next x

    That should work for you.
    [vb5 & starting to move to vb2008] I appreciate the help I get from everyone. Thank you.

  7. #7

    Thread Starter
    New Member
    Join Date
    Sep 2007
    Posts
    5

    Re: Help With Winsock ( Send Packet )

    The game to which I want to send this information to him finds walking, therefore its connection when putting netstat - n is this:



    The Code:

    Code:
    Private Sub Command1_Click()
    Dim myArr(1) As Byte
    myArr(0) = 5
    myArr(1) = 0
    Winsock1.Close
    Winsock1.RemoteHost = "201.212.0.66"
    Winsock1.RemotePort = 7666
    Winsock1.Connect 
    For x = 0 To 1
    Winsock1.SendData myArr(x)
    Next x
    End Sub
    The error is the same one:




  8. #8
    Fanatic Member drivenbywhat's Avatar
    Join Date
    Jan 2007
    Location
    VA - USA
    Posts
    866

    Re: Help With Winsock ( Send Packet )

    "The game to which I want to send this information to him finds walking", what does that mean? "him finds walking"???????????

    Anyways, that error that you are getting is due to the state of the connection. What game is it that has the connection established already? Is it one you made? If it's not, do you know if that game uses winsock? Do you know what commands it expects? Also, is that game's port listening to a connection? Does it have multiple winsock controls to accept more than one connection? If it's already established and only has 1 winsock control listening, it can't establish yet another connection to it.
    [vb5 & starting to move to vb2008] I appreciate the help I get from everyone. Thank you.

  9. #9

    Thread Starter
    New Member
    Join Date
    Sep 2007
    Posts
    5

    Re: Help With Winsock ( Send Packet )

    ...

    Last edited by Jorgitoh; Oct 12th, 2007 at 09:24 AM.

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