need server client connection code in android application -


i new android , need simple http connection codes client server(local server in network) communication in android application.the connection starts when application started , if there update in server should notified on client , server response must based on client request. please help. thanks

socket socket; inputstream is; outputstream os; string hostname; int port;  public void connect() throws ioexception {   socket = new socket(hostname, port);   = socket.getinputstream();   os = socket.getoutputstream(); }  public void send(string data) throws ioexception {   if(socket != null && socket.isconnected()) {     os.write(data.getbytes());     os.flush();   } }  public string read() throws ioexception {   string rtn = null;   int ret;   byte buf[] = new byte[512];   while((ret = is.read(buf)) != -1) {     rtn += new string(buf, 0, ret, "utf-8");   }   return rtn; }  public void disconnect() throws ioexception {   try {     is.close();     os.close();     socket.close();   } {     = null;     os = null;     socket = null;   }  } 

connect, send, read, disconnect :)


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -