How to send multi data bytes within single packet using winsock

Posted on 2006-04-15
Medium Priority
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
  • 2
  • 2
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16461048
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

ID: 16464248
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

ID: 16528666
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 86

Accepted Solution

Mike Tomlinson earned 1500 total points
ID: 16528763
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

850 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