LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 04-24-2007, 09:20 AM   #1
ashlesha
Member
 
Registered: May 2005
Location: PA
Distribution: Ubuntu
Posts: 204

Rep: Reputation: 30
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.
 
Old 04-24-2007, 06:36 PM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
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.
 
Old 04-24-2007, 08:23 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,103

Rep: Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117
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.
 
Old 04-24-2007, 09:02 PM   #4
ashlesha
Member
 
Registered: May 2005
Location: PA
Distribution: Ubuntu
Posts: 204

Original Poster
Rep: Reputation: 30
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.
 
Old 04-25-2007, 10:45 PM   #5
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bad data in socket read function nhydra Programming 2 05-08-2006 03:16 AM
unix/socket programming, which book should i read first ??? b0nd Linux - General 2 05-06-2006 12:47 AM
cannot read data at server socket, though client socket sends it jacques83 Linux - Networking 0 11-15-2005 01:58 PM
Open office read only, K-write read/write mode lwtvh Linux - Newbie 1 07-19-2003 11:33 AM
Read() function In "socket.h" RAW_STREAM Penguinizer Programming 3 02-22-2003 01:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 05:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration