OBEX: problems with get()
Hi, I'm coding a server-client app. The server is on a PC, and the client on a mobile phone. I want to transfer some files from the PC to the mobile phone, using obex get function. This is the code that I have:
Server:
publicvoid run(){
startButton.setEnabled(false);
updateStatus(local.getFriendlyName());
UUID uuid =new UUID("8841",true);
String url ="btgoep://localhost:" + uuid +";name=reproductor_video;authenticate=false;master=false;encrypt=false";
try{
//updateStatus("epa");
sn = (SessionNotifier)Connector.open(url);
updateStatus("[server:] Now waiting for a client to connect");
}catch (Exception e){
updateStatus("Error: "+e.getCause());
}
try{
sn.acceptAndOpen(this);
updateStatus("[server:] A client is now connected");
}catch (Exception ex){
updateStatus("Error: "+ex.getCause());
}
}
publicint onConnect(HeaderSet request, HeaderSet reply){
updateStatus("[server:] The client has created an OBEX session.");
return ResponseCodes.OBEX_HTTP_OK;
}
publicint onGet(Operation op){
try{
hs = op.getReceivedHeaders();
String path ="C:/UPL/"+hs.getHeader(HeaderSet.NAME).toString();
File f =new File(path);
InputStream is =new FileInputStream(f);
byte filebytes [] =newbyte [is.available()];
updateStatus(path+"\nTama駉: "+is.available());
is.read(filebytes);
is.close();
OutputStream os = op.openOutputStream();
os.write(filebytes);
os.close();
op.close();
}catch (IOException ex){
updateStatus(ex.toString());
ex.printStackTrace();
}
return ResponseCodes.OBEX_HTTP_OK;
}
publicvoid onDisconnect(HeaderSet req, HeaderSet resp){
updateStatus("[server:] The client has disconnected the OBEX session");
}
And the client:
publicvoid run(){
servicio.append("conectado1\n");
try{
cs = (ClientSession) Connector.open(connectionURL);
}catch (IOException ex){
servicio.append(ex.toString());
ex.printStackTrace();
}
servicio.append("conectado2\n");
HeaderSet hs;
hs = cs.createHeaderSet();
hs.setHeader(HeaderSet.NAME, name);
servicio.append("conectado3\n");
try{
cs.connect(hs);
}catch (IOException ex){
servicio.append(ex.toString());
ex.printStackTrace();
}
servicio.append("conectado4\n");
try{
putop = cs.get(hs);
InputStream is = putop.openInputStream();
path = System.getProperty("fileconn.dir.memorycard");
path=path+"upl/";
filecon = (FileConnection) Connector.open(path, Connector.READ_WRITE);
if (!filecon.exists())
filecon.mkdir();
filecon = (FileConnection) Connector.open(path+name, Connector.READ_WRITE);
if (!filecon.exists())
filecon.create();
OutputStream os = filecon.openOutputStream();
int len;
while (is.available()>=0 && (len =is.read(data))>0){
os.write(data, 0, len);
}
is.close();
os.close();
}catch (IOException ex){
servicio.append(ex.toString());
ex.printStackTrace();
}
try{
cs.disconnect(null);
}catch (IOException ex){
ex.printStackTrace();
}
synchronized (this){
try{
wait (5000);
}catch (InterruptedException ex){
ex.printStackTrace();
}
}
conectar("playlist.txt");
}
the first time the file is downloaded correctly, but the second time, the app gets blocked in cs.connect(hs);
Can anybody help me? Thanks

