how to send structures in winsock senddata method? 
Author Message
 how to send structures in winsock senddata method?

Hello everyone. I'm an unix guy trying to write a winsock client in VB
to existing server that is running on UNIX. This unix server listens on
a port. It is expecting messages in the form of structures. The
structure itself contains different datatypes. I created a recordset on
VB side. I connected to unix server using connect of winsock control. I
filled the record set with proper data, and now I want to send it to
unix machine. The senddata method of winsock is expecting the data in
byte order form. How do I make this structure
byte ordered? What is this byte order anyway? I'll be so greatful for
your help.

Surya



Wed, 09 Aug 2000 03:00:00 GMT  
 how to send structures in winsock senddata method?

The first thing you'll need is an apiu call that copies your structure in
VB to a byte array. The second thing to watch is byte ordering (A long is 4
bytes only VB stores them the opposite way to unix). Here is some sample
code that may help you.

Private Const BufferSize = 1024
Private Const TwoLongs = 8

Private Type SocketPacket
    PacketSize As Long
    TextSize As Long
    PacketBuffer(1 To BufferSize) As Byte
End Type

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
    (hpvdest As Any, hpvSource As Any, ByVal cbCopy As Long)

   Dim NewPacket As SocketPacket
    Dim TempString As String
    Dim LongReverse(1 To 4) As Byte
    Dim StringLength As Integer
    Dim PacketBuffer() As Byte

    TempString = "1234567890" + Chr$(0)
    StringLength = Len(TempString)

    NewPacket.PacketSize = BufferSize + TwoLongs
    NewPacket.TextSize = StringLength

    ReDim PacketBuffer(NewPacket.PacketSize - 1)

    Call CopyMemory(NewPacket.PacketBuffer(1), ByVal TempString,
(Len(TempString) + 1))
    Call CopyMemory(PacketBuffer(0), NewPacket, Len(NewPacket))

    LongReverse(1) = PacketBuffer(3)
    LongReverse(2) = PacketBuffer(2)
    LongReverse(3) = PacketBuffer(1)
    LongReverse(4) = PacketBuffer(0)
    PacketBuffer(0) = LongReverse(1)
    PacketBuffer(1) = LongReverse(2)
    PacketBuffer(2) = LongReverse(3)
    PacketBuffer(3) = LongReverse(4)
    LongReverse(1) = PacketBuffer(7)
    LongReverse(2) = PacketBuffer(6)
    LongReverse(3) = PacketBuffer(5)
    LongReverse(4) = PacketBuffer(4)
    PacketBuffer(4) = LongReverse(1)
    PacketBuffer(5) = LongReverse(2)
    PacketBuffer(6) = LongReverse(3)
    PacketBuffer(7) = LongReverse(4)

    Winsock1.SendData PacketBuffer

Quote:

> Hello everyone. I'm an unix guy trying to write a winsock client in VB
> to existing server that is running on UNIX. This unix server listens on
> a port. It is expecting messages in the form of structures. The
> structure itself contains different datatypes. I created a recordset on
> VB side. I connected to unix server using connect of winsock control. I
> filled the record set with proper data, and now I want to send it to
> unix machine. The senddata method of winsock is expecting the data in
> byte order form. How do I make this structure
> byte ordered? What is this byte order anyway? I'll be so greatful for
> your help.

> Surya



Mon, 21 Aug 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. winsock problem sending large strings (winsock.senddata)

2. Winsock Senddata method - confusing?!

3. senddata method problem in winsock control

4. Winsock Senddata method - confusing?!

5. SendData method for winsock control 6.0

6. MSWINSCK.OCX SendData() Method failing to send to network

7. Sending multiple strings with SendData (Winsock)

8. Winsock SendData, sending it too fast for reciever

9. Possible to send structure with MS-WINSOCK?

10. Sending a structure with Microsoft WINSOCK controll ?

11. Send structured data using Winsock API

12. Sending structures via winsock??

 

 
Powered by phpBB® Forum Software