Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7029073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:29:25+00:00 2026-05-28T00:29:25+00:00

I would like to understand how socket work, especially I need some code samples

  • 0

I would like to understand how socket work, especially I need some code samples for server side to receive the stream sent by mediarecorder from the device.

Thank you very much for any help.

My real final intent is to talk in device and listen it on PC, just one direction.

At moment I am able to send out the stream using the following code:

String hostname = "192.168.1.10";
int port = 8000;
Socket socket = null;
    try {
        socket = new Socket(InetAddress.getByName(hostname), port);
    } catch (UnknownHostException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

ParcelFileDescriptor pfd = ParcelFileDescriptor.fromSocket(socket);

recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(pfd.getFileDescriptor());

    try {
        recorder.prepare();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

recorder.start();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:29:26+00:00Added an answer on May 28, 2026 at 12:29 am

    Seems ok, but I would personally prefer to buffer the audio on the device and send it to the server from another thread instead of tying the recorder to the socket directly like you did. Because buffering locally will allow you to handle connection breaks gracefully.

    Imagine you’re recording and user goes through a tunnel and loses internet connection — if you’re streaming directly, the socket would close and the user would be annoyed 🙂 However, if you are buffering the data locally, you can reestablish the connection and continue sending the audio to the server from where you left off, and hopefully the user doesn’t even have to know that a break in the connection just happened, because it just magically works.

    In order to get that to work, you’d have to write the recording to a local buffer and have a separate thread check for new data on that buffer and send to the server as soon as possible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know this to understand why some games like Mario is
I would like to understand that what is Mesh Object and its conection with
I would like to understand what class << self stands for in the next
I would like to understand how object deletion works on python. Here is a
I am developing a Rails application and would like to understand when to use
I would like to better understand the basic steps needed to a take an
I would like to know and understand the steps involved in fetching mail from
I would like to know about the Invoke(delegate) method. I do not understand why
I would like to write a vulnerable program, to better understand Stack Overflow (causes)
I would like to upload a picture to Facebook event. I don't understand the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.