Results 1 to 8 of 8

Thread: Winsock

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Posts
    67

    Post

    How the hell are you suppost to use winsock??
    I can draw the control but how do i send the commands over a network

  2. #2
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Galway, Ireland
    Posts
    316

    Post

    Try this???

    This function is used to send data to a specific destination.

    The following User Defined Type (UDT) is required:

    Type sockaddr

    sa_family As Integer
    sa_data(14) As Byte

    End Type

    Where:


    sa_family = For TCP/IP this should be the value of AF_INET (AF_INET = 2).
    sa_data(14) = Interpretation of this data is based on sa_family. An internet address could be stored in the first 6 bytes of sa_data and the other 8 bytes could be zeroed.

    The following function declaration is required:


    Declare Function sendto Lib "wsock32.dll" (ByVal s As Long, ByRef buf As Any, ByVal buflen As Integer, ByVal flags As Integer, ByRef toaddr As sockaddr, ByRef tolen As Integer) As Integer


    Where:


    s = A descriptor identifying a connected socket
    buf = A buffer for the incoming data
    buflen = The length of buf
    Flags = Specifies the way in which the call is made
    toaddr = An optional pointer to the address of the target socket
    tolen = The size of the address in toaddr

    If no error occurs, sendto() returns the to number of bytes sent. This may be less than the number indicated by buflen. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code may be retrieved by calling WSAGetLastError().

  3. #3
    Lively Member
    Join Date
    Oct 1999
    Location
    Sheffield, Derbyshire, UK
    Posts
    68

    Post

    Ha Ha, I dont think thats quite what he wants, John!!
    Draper, get a life and do some RESEARCH. Every1 else has to, why shouldnt you? There are loads of tutorials and sample progs out there, try 1 of them. Failing that, ring knowles!

    ------------------
    jimmy
    ICQ:35813919
    mail:[email protected]

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Posts
    67

    Post

    Get a life lamer jimdalby
    yes i do know you but grow up
    People are suppsed to be mature

  5. #5
    Hyperactive Member razzaj's Avatar
    Join Date
    Oct 1999
    Location
    jounieh
    Posts
    261

    Post


    well first u have to know that there exists 2 types of protocols supported by vb
    UDP and TCP ..
    the difference (the simple way )
    UDP : allows connections between computers but (peer to peer) no server
    TCP : one computer is to be the server
    and the others clients


    i suggest u start with the udp protocol
    it is much easier , here is a small example :


    draw a winsock control ... ok .. good
    right click and set the protocol property to UDP_"something" ...

    1- in the form_load sub put the following code :

    winsock1.remotehost = "here put the ip address of the computer u wish to connect to"
    winsock1.remoteport = 1001 ' here u can choose any number given that it does not conflict with any other device.this number is the port on which the remote host will be recieving data.
    winsock1.localport = 1002 ' this the port ur computer will be receving data on
    winsock1.bind 1002 ' this is to bind ur port to the remote computer port


    - now on the form place 2 text boxes :
    and go back to the code section and paste this :


    Private Sub Text2_KeyPress(KeyAscii As Integer)

    If KeyAscii = 13 Then
    Winsock1.SendData Text2
    Text2 = ""
    End If

    End Sub

    Private Sub Winsock1_DataArrival(by val bytesTotal As Long)

    Dim str As String
    Winsock1.GetData str
    Text1 = str

    End Sub

    on the other computer u should make the same program but .. bdont forget to chasge the content in the form_load just switch the port numbers and replace the ip number with the right one ....
    basicaly that is it .... if u find any problem just message me back ...(coz u might )

    - regards -
    - razzaj -



    [This message has been edited by razzaj (edited 11-26-1999).]

  6. #6
    New Member
    Join Date
    Nov 1999
    Location
    Cebu, Philippines
    Posts
    15

    Post

    And this is for the "SERVER"

    'for the module

    Public intMax As Long

    'for the form_load

    Winsock1(0).LocalPort = 1001 'what ever you want!
    Winsock1(0).Listen


    'for the Winsock1_ConnectionRequest

    If Index = 0 Then
    intMax = intMax + 1
    Load Winsock1(intMax)
    Winsock1(intMax).LocalPort = 1001
    Winsock1(intMax).Accept requestID
    End If



    ------------------

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Posts
    67

    Post

    Thanks for the help but it keep erroring and saying that there is a syntax error in the line
    Private Sub Winsock1_DataArrival(by value bytesTotal As Long)
    I don't know why
    Please help
    Thanks

    [This message has been edited by death (edited 11-27-1999).]

  8. #8
    Hyperactive Member razzaj's Avatar
    Join Date
    Oct 1999
    Location
    jounieh
    Posts
    261

    Post

    of course it should .. u are writing it the wrong way , in my example i wrote it wront to ... so hwere how it is to be writen :

    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)

    .... the routine i gave u in my example before ...

    End Sub

    note : this example has nothing to do with what jazz wrote .. what jazz wrote is a part of the TCP protocole way to do it ... what i gave u is the UDP way to do it ...

    - regards -
    - razzaj -

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