You Are Here:

Community: Developer Discussion Boards

#1 Old Sending files from mobile to PC with OBEX - 2008-03-03, 13:27

Join Date: Mar 2008
Posts: 2
Raspa
Offline
Registered User
Hi.

I started messing around with bluetooth last week, and I already managed to broadcast files from my pc to any bluetooth device I can find.

Now I want to do the oposite, send files from my mobile to the pc.
I want to do this without the need of a custum application for the mobile.

The problem is that the mobile does not see my computer when I try to send a file. Right now i'm using an Nokia 6280.

I'm using bluecove + windows xp stack.

Here's my server code
PHP Code:
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;

import javax.bluetooth.*;
import javax.microedition.io.Connector;
import javax.obex.*;

public class 
RecieveFile {



    public static 
void main(String[] argsthrows IOException {
        
        
UUID obexPushObject = new UUID(0x1105);
        
UUID L2CAP = new UUID(0x0100);
        
UUID RFCOMM = new UUID(0x0003);
        
              
        
LocalDevice localDevice LocalDevice.getLocalDevice();
        
localDevice.setDiscoverable(DiscoveryAgent.GIAC);
        
        
ServiceRecord serviceRecord null;
        
DataElement elm null;
        
        
int[] attrIDs = new int[2];
        
        
        
        
System.out.println("Opening service in " LocalDevice.getLocalDevice().getBluetoothAddress());

        
SessionNotifier serverConnection = (SessionNotifierConnector.open("btgoep://localhost:1105;name=lab");
        
System.out.println("Teste");
               
        
serviceRecord localDevice.getRecord(serverConnection);
        
        
    
DataElement serviceClassIDList serviceRecord.getAttributeValue(0x01);
    
DataElement newSCList = new DataElement (DataElement.DATSEQ);
    
Enumeration v = (Enumeration)serviceClassIDList.getValue();
    while (
v.hasMoreElements()) {
            
DataElement de = (DataElement)v.nextElement();
            if (!(
de.getValue().equals(new UUID (0x1101))))
            
newSCList.addElement(de);
        }
    
newSCList.addElement(new DataElement(DataElement.UUID, new UUID(0x1105)));
    
serviceRecord.setAttributeValue(0x01newSCList);
        
        
DataElement protocolDescriptorList serviceRecord.getAttributeValue(0x04);
    
DataElement newProtDescList = new DataElement (DataElement.DATSEQ);
        
= (Enumeration)protocolDescriptorList.getValue();
    while (
v.hasMoreElements()) {
            
DataElement de = (DataElement)v.nextElement();
            
newProtDescList.addElement(de);
    }
            
    
DataElement obexDescriptor = new DataElement(DataElement.DATSEQ);
    
obexDescriptor.addElement(new DataElement(DataElement.UUID, new UUID(0x08)));

    
newProtDescList.addElement(obexDescriptor);
    
serviceRecord.setAttributeValue(0x04newProtDescList);
        
        
DataElement sfl = new DataElement (DataElement.DATSEQ);
    
sfl.addElement(new DataElement (DataElement.U_INT_11));
    
sfl.addElement(new DataElement (DataElement.U_INT_12));
    
sfl.addElement(new DataElement (DataElement.U_INT_14));
    
sfl.addElement(new DataElement (DataElement.U_INT_15));
    
sfl.addElement(new DataElement (DataElement.U_INT_16));
    
sfl.addElement(new DataElement (DataElement.U_INT_1255));
    
serviceRecord.setAttributeValue(0x0303sfl);
                    
                    
//Update service availability
    
serviceRecord.setAttributeValue(0x0008, new DataElement (DataElement.U_INT_1255));

                
//Update Profile Descriptor List
    
DataElement profileDescriptorList = new DataElement(DataElement.DATSEQ);
    
DataElement profileDescriptor = new DataElement(DataElement.DATSEQ);
    
profileDescriptor.addElement(new DataElement(DataElement.UUID, new UUID(0x1105)));
    
profileDescriptor.addElement(new DataElement(DataElement.U_INT_2256));
    
profileDescriptorList.addElement(profileDescriptor);
    
serviceRecord.setAttributeValue(0x0009profileDescriptorList);


        try{
           
LocalDevice.getLocalDevice().updateRecord(serviceRecord);
        }catch(
ServiceRegistrationException e)
        {
            
System.out.println(e.getMessage());
        }
        

        
int count 0;
        while(
count 2) {
            
RequestHandler handler = new RequestHandler();
            
serverConnection.acceptAndOpen(handler);
            
System.out.println("Received OBEX connection " + (++count));
        }
    }

    private static class 
RequestHandler extends ServerRequestHandler {

        public 
int onPut(Operation op) {
            try {
                
HeaderSet hs op.getReceivedHeaders();
                
String name = (String) hs.getHeader(HeaderSet.NAME);
                if (
name != null) {
                    
System.out.println("put name:" name);
                }

                
InputStream is op.openInputStream();

                
StringBuffer buf = new StringBuffer();
                
int data;
                while ((
data is.read()) != -1) {
                    
buf.append((chardata);
                }

                
System.out.println("got:" buf.toString());

                
op.close();
                return 
ResponseCodes.OBEX_HTTP_OK;
            } catch (
IOException e) {
                
e.printStackTrace();
                return 
ResponseCodes.OBEX_HTTP_UNAVAILABLE;
            }
        }
    }

Right now I'm not that intrested in the file handeling after a connection is recieved.

Can anybody tell me where my problem is?

Thanks in advance

Raspa
Last edited by Raspa : 2008-03-03 at 15:44.
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending an SMS from Mobile to Servlet?!! omarZam General Messaging 0 2006-06-04 18:06
HELP-cookie files' path in symbian os mobile phone foods33 General Symbian C++ 0 2005-10-10 10:31
sending files via blue tooth in 6630 RaFeeL Bluetooth Technology 5 2005-10-05 10:59
Sending files from PC to phone florinstoian Bluetooth Technology 4 2003-12-02 22:50
Sending several files without using SIS stopin General Symbian C++ 0 2003-07-10 17:32

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia