473,224 Members | 1,861 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,224 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 11442
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.
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.