473,387 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

sending voice file using socket programming

Hi i want to record an audio file and send it using UDP . I have server/client program and i'm able to send text file and recive that into another file .But how do i send audio file ..can anyone help me out here ??????

I'm using Unix stations and C .
Feb 27 '08 #1
9 11509
Hi i want to record an audio file and send it using UDP . I have server/client program and i'm able to send text file and recive that into another file .But how do i send audio file ..can anyone help me out here ??????

I'm using Unix stations and C .
Hi,

have you tried sending the audio file as a text? That should work, or I don't see your problem.
Feb 28 '08 #2
sicarie
4,677 Expert Mod 4TB
Hi i want to record an audio file and send it using UDP . I have server/client program and i'm able to send text file and recive that into another file .But how do i send audio file ..can anyone help me out here ??????

I'm using Unix stations and C .
Are you sure you want to use UDP? That sounds more like you are trying to send streaming audio, not transferring a file from one computer to another...

If you send the file via UDP, you will lose data, and you will not be able to resend that data.
Feb 28 '08 #3
here is the code i'm trying to integrate to be able to send/transfer audio file. I just want to save an audio file and want to get to other computer thats all..Plz if someone can do some changes in the code that wud be awesome coz i'm not too aware of network programming .this is probably my first attempt !!!
rt now i'm broadcasting the file :
Broadcasting Code :
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <errno.h>
  5. #include <string.h>
  6. #include <sys/types.h>
  7. #include <sys/socket.h>
  8. #include <netinet/in.h>
  9. #include <arpa/inet.h>
  10. #include <netdb.h>
  11.  
  12. #define SERVERPORT 4950 // the port users will be connecting to
  13.  
  14. int main(int argc,char *argv[])
  15. {
  16. int sockfd;
  17. struct sockaddr_in their_addr; // connector's address information
  18. struct hostent *he;
  19. int numbytes;
  20. int broadcast = 1;
  21. FILE *fp1;
  22. int infile[50000]; //filesize
  23. int *mypointer
  24. char c;
  25. int i = 0;
  26.  
  27. mypointer = infile;
  28.  
  29. if (argc != 3) {
  30. fprintf(stderr,"usage: broadcaster hostname message\n");
  31. exit(1);
  32. }
  33.  
  34. if ((he = gethostbyname(argv[1])) == NULL) { // get the host info
  35. herror("gethostbyname");
  36. exit(1);
  37. }
  38.  
  39. if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
  40. perror("socket");
  41. exit(1);
  42. }
  43.  
  44.  
  45. if (setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &broadcast,
  46. sizeof broadcast) == -1) {
  47. perror("setsockopt (SO_BROADCAST)");
  48. exit(1);
  49. }
  50. fp1 = fopen(argv[2],"r");
  51. while(( c = getc(fp1)) != EOF)
  52. {
  53. infile[i] = c;
  54. i = i+1;
  55. };
  56. their_addr.sin_family = AF_INET; // host byte order
  57. their_addr.sin_port = htons(SERVERPORT); // short, network byte order
  58. their_addr.sin_addr = *((struct in_addr *)he->h_addr);
  59. memset(their_addr.sin_zero, '\0', sizeof their_addr.sin_zero);
  60.  
  61. if ((numbytes=sendto(sockfd, mypointer, i, 0,
  62. (struct sockaddr *)&their_addr, sizeof their_addr)) == -1) {
  63. perror("sendto");
  64. exit(1);
  65. }
  66.  
  67. printf("sent %d bytes to %s\n", numbytes, inet_ntoa(their_addr.sin_addr));
  68.  
  69. close(sockfd);
  70.  
  71. return 0;
  72. }
Listening file :
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <errno.h>
  5. #include <string.h>
  6. #include <sys/types.h>
  7. #include <sys/socket.h>
  8. #include <netinet/in.h>
  9. #include <arpa/inet.h>
  10.  
  11. #define MYPORT 4950 // the port users will be connecting to
  12.  
  13. #define MAXBUFLEN 50000
  14.  
  15. int main(void)
  16. {
  17. FILE *out;
  18. int sockfd;
  19. struct sockaddr_in my_addr; // my address information
  20. struct sockaddr_in their_addr; // connector's address information
  21. socklen_t addr_len;
  22. int numbytes;
  23. char buf[MAXBUFLEN];
  24.  
  25. if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
  26. perror("socket");
  27. exit(1);
  28. }
  29.  
  30. my_addr.sin_family = AF_INET; // host byte order
  31. my_addr.sin_port = htons(MYPORT); // short, network byte order
  32. my_addr.sin_addr.s_addr = INADDR_ANY; // automatically fill with my IP
  33. memset(my_addr.sin_zero, '\0', sizeof my_addr.sin_zero);
  34.  
  35. if (bind(sockfd, (struct sockaddr *)&my_addr, sizeof my_addr) == -1) {
  36. perror("bind");
  37. exit(1);
  38. }
  39.  
  40. addr_len = sizeof their_addr;
  41. if ((numbytes = recvfrom(sockfd, buf, MAXBUFLEN-1 , 0,
  42. (struct sockaddr *)&their_addr, &addr_len)) == -1) {
  43. perror("recvfrom");
  44. exit(1);
  45. }
  46. out = fopen("../thanga/xxxx.c","a");//save in a file
  47. fprintf(out,"got packet from %s\n",inet_ntoa(their_addr.sin_addr));
  48. fprintf(out,"packet is %d bytes long\n",numbytes);
  49. buf[numbytes] = '\0';
  50. fprintf(out,"packet contains \"%s\"\n",buf);
  51. fclose(out);mohan
  52.  
  53. close(sockfd);
  54.  
  55. return 0;
  56. }
  57.  
P.S. Originallly i got this code from a tutorial website.I"m only trying to integrate and make changes to fit my requirement.
Feb 28 '08 #4
sicarie
4,677 Expert Mod 4TB
I updated the thread to avoid further confusion, please let me know if you think it should be modified, and what you'd like it changed to.

Moderator
Feb 28 '08 #5
I updated the thread to avoid further confusion, please let me know if you think it should be modified, and what you'd like it changed to.

Moderator
Hi, i was wondering if someone could provide me with a code how to do the above ???? i'm using unix machines.
Feb 28 '08 #6
Can anyone help me here ????
Mar 1 '08 #7
Hi,

have you tried sending the audio file as a text? That should work, or I don't see your problem.
yes i tried doing that..but i'm getting some garbage value in the receiving text file How do i convert the audio file into text/binary and send and then at the receiving end convert it back ?
Mar 1 '08 #8
Hey,
if you can send a text file between the client/server then you can send an audio file, i think you need make the integer buffer smaller, 50000 is too large, and unnecessary. Also you are missing some brackets () when you use sizeof( ).

Goodluck
Mar 4 '08 #9
Banfa
9,065 Expert Mod 8TB
Also you are missing some brackets () when you use sizeof( ).
The ( and ) on sizeof are optional when that operator is applied to a variable (as opposed to a data type).
Mar 4 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Emil | last post by:
This is my problem: I'm writing a script that... 1. creates a customized pls/m3u playlist 2. sends the pls or a m3u playlist to the webbrowser. The browser should open Winamp/Windows Media...
1
by: Stevio | last post by:
I have a guy asking me about the speed of downloads from his web site. I use ASP code to send the download to the user, and the code I use is basically like this: FileName =...
1
by: Henrik | last post by:
I want to download a file using socket programming (and not httprequest) but the DNS keeps giving me errors "IP is ok, but the attached data is not available" I am doing like this and the...
0
by: Help | last post by:
What are the parameters in the constructor if you are going to send a file over a tcp/ip network using netstream and filestream? I have learned that you are supposed to do something like this:...
7
by: nagasrinivas05 | last post by:
hi, this is srinivas here i am using socket programming to send data to a remote computer using clssocket with namespace system.net and it is working well, but when i am sending continuous data in a...
1
by: nagasrinivas05 | last post by:
hi all, i am using socket programming to display status using class socket my application is working fine when i set the port no as 8221 and when i use the same applcation in another location then...
0
by: romcab | last post by:
Hi guys, I just want to ask if I can used BinaryStream class in .Net to send mpeg file using socket either TCP or UDP? Does the mpeg file will not be corrupted? Hope you can give me an idea or...
1
by: govind161986 | last post by:
When i execute the below mentioned code in .NET 1.1 i get the following error message "A socket operation was attempted to an unreachable host" but when i execute the same code in .NET 2.0 it...
1
by: msabirali | last post by:
I need a sample code to start a program that can receive a jpeg file from server using socket programming. Any code or reference is appreciated.
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.