Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

How we will create, send and receive a voice packet of 20ms of size 100bytes

Asked by jawad on 7 Jan 2013

I want to store my voice samples in a multiple voice packets and then want to store them in a buffer. The buffer size is 100ms and 500bytes. the packets will be played after 20ms interval.

Please help and guide.

5 Comments

jawad on 26 Feb 2013
% SERVER Write a message over the specified port
% 
% Usage - server(message, output_port, number_of_retries)
function server(message, output_port, number_of_retries)
      import java.net.ServerSocket
      import java.io.*
      if (nargin < 3)
          number_of_retries = 20; % set to -1 for infinite
      end
      retry             = 0;
      server_socket  = [];
      output_socket  = [];
      while true
          retry = retry + 1;
          try
              if ((number_of_retries > 0) && (retry > number_of_retries))
                  fprintf(1, 'Too many retries\n');
                  break;
              end
              fprintf(1, ['Try %d waiting for client to connect to this ' ...
                          'host on port : %d\n'], retry, output_port);
              % wait for 1 second for client to connect server socket
              server_socket = ServerSocket(output_port);
              server_socket.setSoTimeout(1000);
              output_socket = server_socket.accept;
              fprintf(1, 'Client connected\n');
              output_stream   = output_socket.getOutputStream;
              d_output_stream = DataOutputStream(output_stream);
              % output the data over the DataOutputStream
              % Convert to stream of bytes
              fprintf(1, 'Writing %d bytes\n', length(message))
              d_output_stream.writeBytes(char(message));
              d_output_stream.flush;
              % clean up
              server_socket.close;
              output_socket.close;
              break;
          catch
              if ~isempty(server_socket)
                  server_socket.close
              end
              if ~isempty(output_socket)
                  output_socket.close
              end
              % pause before retrying
              pause(1);
          end
      end
  end
jawad on 26 Feb 2013
 system('matlab -nodisplay -r YourScriptName &')
jawad on 26 Feb 2013

Dear Robert can you please explain to me how i will execute these client and server on the same machine. Kindly explain it step by step as I am new with the matlab and also with the networking portion of Matlab. I have found this code on the Mathworks forum.

jawad

Products

No products are associated with this question.

1 Answer

Answer by jawad on 7 Jan 2013
Accepted answer

No

In MatLab.

If you can do in Simulink, then sure.

1 Comment

jawad on 26 Feb 2013

Dear Reinaldo Flamino I have downloaded your file Judp.m file. But I don't know how i will run it. can you please explain me step by step. As i am new to Matlab and also network side. Thanks

jawad

Contact us