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 8781939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:26:20+00:00 2026-06-13T20:26:20+00:00

what is the best approach of connecting android to server and ip and corresponding

  • 0

what is the best approach of connecting android to server and ip and corresponding port? THis connection doesn’t need to be all the time, but I am assuming I will send and recive files (in byte arrays or streams).

Thanks

  • 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-06-13T20:26:22+00:00Added an answer on June 13, 2026 at 8:26 pm

    Since the Android Development Tools are native to Java, you can use simple Java Socket APIs to accomplish this goal (see ServerSocket and Socket).

    Server Code

    You must start by opening a ServerSocket on your host computer by defining a port to listen on:

    ServerSocket ss = new ServerSocket([some_port]);
    

    Then you must begin listening for a client by calling ss.accept(). This method will block until a client connects:

    Socket my_socket = ss.accept();
    

    You now have a socket on your server that you can manipulate as you wish (probably through the use of ObjectInputStream and ObjectOutputStream):

    ObjectOutputStream out = new ObjectOutputStream(my_socket.getOutputStream());
    ObjectInputStream in= new ObjectInputStream(my_socket.getInputStream());
    

    Client Code

    You must establish a connection with the server that you have just created. You will do this by initializing a socket and passing in the IP address of your server (usually localhost for most testing purposes) and the port number on which your server is currently listening:

    Socket socket = new Socket("localhost", [some_port]);
    

    Again, establish some streams for communication:

    ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
    ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
    

    And there you have it! You can now easily communicate with a server from an Android device. It is much simpler than you would think.

    Please note, however, that this architecture implements TCP, which is much slower than UDP and will not work for any type of fast-paced data intensive games, but should accomplish your goals given your description above.

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

Sidebar

Related Questions

I'm wondering about the best approach to designing a DB connection manager for a
I'm trying to figure out the best way to approach this. I have a
I am looking for best approach to handling database connection. I have designed my
Possible Duplicate: How can I monitor the network connection status in Android? I need
What's the best approach to import multiple lines from a text_area in a form?
What is the best approach to handle authentication on a bunch of Javascript actions
What is the best approach for mocking out a static class in c#. For
What is the best approach to render a large number of 2D graphical elements
What is a best approach to make a function or set of statements thread
What is the best approach, simple string concatenation or string.format ? For instance, what

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.