Results 1 to 8 of 8

Thread: best way to send data over network?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    new zealand (kiwi)!
    Posts
    202

    best way to send data over network?

    using VB6
    i want to send small amount of data (<50 bytes) between 2 computers on a network every 1 minute.
    error checking will be in the data, so no security, etc required.

    What is the best way ?
    Any code examples ?

    thanks

  2. #2
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Three Anchor Bay, Cape Town, South Africa
    Posts
    769
    Use a propertybag object and send the propertybag.content string. Because the string is a native type, you will minimise your marshalling and the data size is usually pretty good.

    Another option would be zip an xml file. XML is usually pretty large, but compressed, you can get some really good sizes. When you uncompress it, you will have all the nice XML functionality like format checking using XSD, format transformations using XSLT etc.

    Heres a good article on when to use xml: The XML Litmus Test

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    new zealand (kiwi)!
    Posts
    202
    thanks, but i need more lower level help!
    how to send / recieve a few bytes...
    winsocket i guess..

  4. #4
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

  5. #5
    New Member
    Join Date
    Nov 2004
    Posts
    2

    Smile

    The easiest way is to use UDP in the Winsock control. Remember it is connectionless and the message is not guaranteed to arrive at the destination. So you have to plan for that!

    example: Simplistic but not too far off!

    VB Code:
    1. 'Sender:
    2.  
    3.     udpSocket.RemoteHost = cmbRemoteHost.Text ' IP or DNS
    4.     udpSocket.RemotePort = Val(txtRemotePort.Text) ' like 2001
    5.  
    6.     udpSocket.SendData msg$
    7.  
    8. 'Reciever: DataArrival event fires
    9. Private Sub udpSocket_DataArrival(ByVal bytesTotal As Long)
    10.     Dim strData As String
    11.     Dim strTag  As String
    12.    
    13.     On Error Resume Next
    14.     Err = 0
    15.    
    16.     Beep
    17.    
    18.     udpSocket.GetData strData
    19.    
    20.     If Err Then
    21.         txtStatus.Text = Error
    22.         Exit Sub
    23.     End If
    24.    
    25.    txtStatus.Text = strData
    26. End

  6. #6
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787
    Originally posted by altwies
    The easiest way is to use UDP in the Winsock control. Remember it is connectionless and the message is not guaranteed to arrive at the destination. So you have to plan for that!

    example: Simplistic but not too far off!

    VB Code:
    1. 'Sender:
    2.  
    3.     udpSocket.RemoteHost = cmbRemoteHost.Text ' IP or DNS
    4.     udpSocket.RemotePort = Val(txtRemotePort.Text) ' like 2001
    5.  
    6.     udpSocket.SendData msg$
    7.  
    8. 'Reciever: DataArrival event fires
    9. Private Sub udpSocket_DataArrival(ByVal bytesTotal As Long)
    10.     Dim strData As String
    11.     Dim strTag  As String
    12.    
    13.     On Error Resume Next
    14.     Err = 0
    15.    
    16.     Beep
    17.    
    18.     udpSocket.GetData strData
    19.    
    20.     If Err Then
    21.         txtStatus.Text = Error
    22.         Exit Sub
    23.     End If
    24.    
    25.    txtStatus.Text = strData
    26. End
    thats only one of the 2 protocalls winsock has, it has a connection one as well which is MORE likly to get data there

    www.winsockvb.com

  7. #7
    New Member
    Join Date
    Nov 2004
    Posts
    2
    True! There are connected sockets but UDP will be the lease complicated of the two and consume the least network resources, especially because a connection with all of its handshaking does not need to be created and destroyed each time. On the other hand, if network resources were sufficient and you wanted to leave the connection open for indeterminate amounts of time, a connected socket would due as well. The code to handle this is not too much more complicated but you would have to consider handling or disabling socket timeouts and other similar things.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    new zealand (kiwi)!
    Posts
    202
    Hi thanks both for your comments.
    A simple UDP will do me , I think.

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