LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   socket programming function to read/write integers? (https://www.linuxquestions.org/questions/linux-networking-3/socket-programming-function-to-read-write-integers-548594/)

ashlesha 04-24-2007 09:20 AM

socket programming function to read/write integers?
 
Hi,

I want to know if there is a socket programming function that lets you read and write integers instead of characters --

I want to transmit a wav file (or raw pcm data) across the network using UDP and using the read and write functions which pass character strings across is very slow --

Any pointers?

Thanks,
Ashlesha.

wjevans_7d1@yahoo.co 04-24-2007 06:36 PM

Um, the read() and write() functions don't pass character "strings" (NUL-delimited sets of characters); they pass raw data, pure and simple.

Wanna shift into a lower gear and try this question again? It doesn't seem to make sense yet.

syg00 04-24-2007 08:23 PM

What language ???. Python handles the socket data as strings IIRC (haven't looked in a good while), but you should be able to overload the functions.

ashlesha 04-24-2007 09:02 PM

hi,
Thanks for you answers --
I am using C --
so the read and write dont pass data as null terminated strings -- however, in the definition, the second argument that is passed to the function is a character pointer -- so I am converting my 16bit PCM data to 8bit character data and then sending it across --

so my question is : is there a function that lets you pass an integer array? -- hopefully this is better worded -

-Ashlesha.

wjevans_7d1@yahoo.co 04-25-2007 10:45 PM

According to the man page, the second parameter is not of type char *, but rather of type void *. This emphasizes that it doesn't matter what type of data is used. All you need to do is specify the number of bytes correctly.

If you were sending an array of char (which you're not), the number of bytes would be the number of chars, since a character occupies one byte. If your array contains, say, 346 integers, the number of bytes you will be writing or reading is

Code:

346*sizeof(int)
Hope this helps.


All times are GMT -5. The time now is 03:11 AM.