android - To share data through wifi-hotspot between two mobiles? -


i m trying share data through wifi-hotspot have search every could`t find thing..so body have idea please share it.. , should through wifi-hotspot not wifi-direct..

//sever code

            try {                 serversocket ss = new serversocket(400);                 tt.settext("running");                 while (true)                 {                     socket s = ss.accept();                     fileinputstream fis = new fileinputstream("sdcard/dcim/123.jpeg");                     byte[] buffer = new byte[fis.available()];                     fis.read(buffer);                      objectoutputstream oos = new objectoutputstream(s.getoutputstream());                     oos.writeobject(buffer);                     oos.close();                     s.close();                 }             } catch (ioexception e) {                  toast.maketext(mainactivity.this,""+e,toast.length_long).show();             }          }     }); } 

///client code....

            try {                 socket s = new socket(txtip.gettext().tostring(),integer.parseint(txtport.tostring()));                 objectinputstream oos = new objectinputstream(s.getinputstream());                      byte[] buffer = (byte[]) oos.readobject();                     fileoutputstream fos = new fileoutputstream("/storage/123.jpeg");                     fos.write(buffer);              } catch (ioexception e) {                 toast.maketext(mainactivity.this,""+e,toast.length_long).show();             } catch (classnotfoundexception e) {                  toast.maketext(mainactivity.this,""+e,toast.length_long).show();             }          }     }); } 

i wrote small awful library did this. can use java sockets.

have 1 device run serversocket in app, socket can listen connections (like server). need check on port serversocket listening (google it). need ip address of device, there few way: can wifimanager (google it).

other device use socket class connect it. can send data in multiple forms: plain strings or if use same app can serialize/deserialize objects.

read bit sockets, after serversocket connection other device, can exchange messages (just keep listening in loop on other thread).


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -