How to send multi data bytes within single packet using winsock

Posted on 2006-04-15
Last Modified: 2013-12-25
I have a problem in my final year project.
I am doing my project as an application of the voice over IP technology.
I did the hardware part that can send and receive the sound with pc serially using the MSComm port "Microsoft communication port"  while the  vb6.0 "visual basic 6.0" will take the sound bytes from the MSComm port and send it in a form of packets using the Winsock.
But in the  VB 6.0  part i have a problem with using the Winsock since the Winsock is taking every sound byte and make it by it self as a packet which caused me an extreme malfunction and overflow in my LAN network.
So I need your help in forming the received sound bytes from the MSComm port to a packet form containing 1000 sound bytes and send it as a single packet in the Winsock.
Question by:tarik_bizri
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    How big is each "sound byte"?...

    What are they being stored in?  A string?  A byte array?

    Make yourself an array of "sound bytes" and add each sound byte to it, keeping track of how many are in it.  When its full, send it off.  Reset your counter...

    Or just concatenate them together as a long string and send that.  You need to make sure the receiver on the other end knows how to distinguish the end of one sound byte from the beginning of the next.  If they are fixed length then it is easy.   If they are variable then you need to make some kind of sound byte delimiter that marks the end of a sound byte.  This way you can seperate out the multiple sound bytes on the other end properly.  This will also let you know if you have received only a partial sound byte.

    Author Comment

    hello  Idle Mind
    the sound byte is a string
    and i cant control the nomber of the sound byte ;received to me from the  MSComm; that i will send thru packets so i will use variable size packets and i will put inside the packet a start byte and size of the packet and an end byte
    i will use forloop inside a dowhile loop to do for  me this idea

    i will try this solution and if it gona work i am gona take it
    and i am very thankfull for ur help

    Author Comment

    okay mr idel mind
    i did solve my problem with the udp protocol
    but i need to order my packet in a certain way that i can read them in the same order
    so i need to add a sequence nomber to the packets at the sending side and at the recieving side if u have any code i would be thankful
    LVL 85

    Accepted Solution

    That's a whole different ball game...and one of the pains in using UDP!

    If you were able to add start/size/end bytes into your packets I don't see why you wouldn't be able to modify it for your latest requirements...

    You need to somehow store your packets as they come in some kind of rearrangeable (sp?) structure...or be able to at least store pointers to them so you can easily retrieve the next piece in the sequence.


    (1) Build a Class to encapsulate your sound bytes and store them in a Linked List fashion.  When you receive a new packet, insert it into your linked list in sorted order.

    (2) Use a collection object and add your packets  to it using their sequence number as the key.

    (3) Use a global string that you insert the packets into using sring manipulation functions like Mid(), Left(), Right().  This could get real slow and ineffecient if your strings are large!

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Hidden and protected sheets 12 48
    Extract Data and filename Macro 20 90
    VBA error replacing data 6 29
    using Access 8 38
    There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now