Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Android
  4. set receiver for Serversocket in android?

set receiver for Serversocket in android?

Scheduled Pinned Locked Moved Android
androidsysadminquestion
1 Posts 1 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 10990385
    wrote on last edited by
    #1

    I am working on app in which I am reading data from a specific port of android. Some one send data on port from web back end and i read it on android device.I want to set a receiver for this but i dont know what action is required for this. My code is here. public class MainActivity extends Activity { Socket socket; private ServerSocket serverSocket; BufferedReader in = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); new Task().execute(); } private class Task extends AsyncTask { @Override protected Void doInBackground(Void... params) { try { serverSocket = new ServerSocket(6066); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { while (true) { socket = serverSocket.accept(); try { in = new BufferedReader(new InputStreamReader(socket.getInputStream())); String msg = null; try { StringBuilder total = new StringBuilder(); String line; while ((line = in.readLine()) != null) { total.append(line); } msg = total.toString(); Log.d("NETWORK-RECEIVE","Message readed!:"+msg); } catch (IOException e) { e.printStackTrace(); Log.d("NETWORK-RECEIVE", "Something goes wrong: IOException"); } } finally { socket.close(); } } } catch (IOException e) { // TODO Auto-generated catch block

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups