Results 1 to 5 of 5

Thread: Need help with Winsock. thanks

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2005
    Posts
    7

    Need help with Winsock. thanks

    Guys, i'm working on converting a VB 6.0 program to VB.net.

    It was a client progam connected to the server by using TCP/IP. In VB 6.0, it was able to send double type straight away to the server using COM component. The problem is when using VB.net socket class, it only allows me to send byte array instead of double type. Is there any way i can send a double variable ? because i don't want to change the server program.

    Thanks

  2. #2
    Frenzied Member ntg's Avatar
    Join Date
    Sep 2004
    Posts
    1,449

    Re: Need help with Winsock. thanks

    Quote Originally Posted by richARD.net
    ...using COM component.
    Which COM component was that ?

    Cheers,
    NTG
    "Feel the force...read the source..."
    Utilities: POPFileDebugViewProcess ExplorerWiresharkKeePassUltraVNCPic2Ascii
    .Net tools & open source: DotNetNukelog4NetCLRProfiler
    My open source projects: Thales SimulatorEFT CalculatorSystem Info ReporterVSS2SVNIBAN Functions
    Customer quote: "If the server has a RAID array, why should we bother with backups?"
    Programmer quote: "I never comment my code. Something that is hard to write should be impossible to comprehend."
    Ignorant quote: "I have no respect for universities, as they teach not practicle stuff, and charge money for"

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2005
    Posts
    7

    Smile Re: Need help with Winsock. thanks

    it is the winsock in VB 6.0

  4. #4
    Frenzied Member ntg's Avatar
    Join Date
    Sep 2004
    Posts
    1,449

    Re: Need help with Winsock. thanks

    When you did a Winsock.SendData DoubleVar, VB6 took that double and converted it to a byte array. I'm really not sure how (or if) you could achieve the same result in .Net without too much trouble. The .Net way would be to serialize an object to send (whether that is a double or any other object) into a memory stream, send the stream and do the reverse process on the other end.

    However, if you can't change the server that could be a problem. This may be an overkill and I hope someone can post a better suggestion, buf if you serialize a double and you copy the memory stream's contents into a byte array, the eight bytes before the last byte of the array are the exact bytes that would be send by the equivalent VB6 process. This is a messy process to say the least...if you can't find another way, you can always use COM Interop and instantiate winsock in your .Net program.

    VB Code:
    1. 'Code to serialize a double
    2.         Dim o As System.IO.MemoryStream = New MemoryStream
    3.         Dim oo As Double = 123.45
    4.         Dim bBuf(128) As Byte
    5.  
    6.         Dim Buffer As New MemoryStream
    7.         Dim Formatter As New Runtime.Serialization.Formatters.Binary.BinaryFormatter
    8.         Formatter.Serialize(Buffer, oo)
    9.         Buffer.Position = 0
    10.         Buffer.WriteTo(o)
    11.         Buffer.Close()
    12.         bBuf = o.ToArray

    Cheers,
    NTG
    "Feel the force...read the source..."
    Utilities: POPFileDebugViewProcess ExplorerWiresharkKeePassUltraVNCPic2Ascii
    .Net tools & open source: DotNetNukelog4NetCLRProfiler
    My open source projects: Thales SimulatorEFT CalculatorSystem Info ReporterVSS2SVNIBAN Functions
    Customer quote: "If the server has a RAID array, why should we bother with backups?"
    Programmer quote: "I never comment my code. Something that is hard to write should be impossible to comprehend."
    Ignorant quote: "I have no respect for universities, as they teach not practicle stuff, and charge money for"

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2005
    Posts
    7

    Re: Need help with Winsock. thanks

    Thanks a lot for ur suggestions.

    Actually i was already using a winsock COM component without any problem in sending data over to the server. but i realized later that the receiving data part can't use "DataArrival" method anymore so i decided to switch to socket class.

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