×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    31

    Unhappy sending strings over bluetooth

    hi
    i develop a bluetooth aplication that when the server and the client are connected, they send a string to each other. Now, i want send more mesagges without doing the process again, just adding a button, but i doesn't work. Can someone help me!!

    Code:
    public void deviceDiscovered(RemoteDevice remoteDevice, DeviceClass deviceClass) {
    
    			RemoteDevice device = servRecord[i].getHostDevice();
                String name = device.getBluetoothAddress();
                servicioCliente.append("device:"+device.toString()+"\n"+"name"+name);
    			
                cancelar(); //cancelamos las busquedas
                
    			try {
    				coneccion =(StreamConnection) Connector.open(urlNaNe);
    				in = coneccion.openDataInputStream();
    				out = coneccion.openDataOutputStream();
    				enviar();
    			} catch(IOException e) {
    				e.printStackTrace();
    			} 
    			
    			
    		}
    	}
    
    	public void enviar() {
    		try {
    			
    			out.writeUTF("Saludos desde el cliente!");
    			out.flush();
    			String mensajeLlega = in.readUTF();
    			textoCli.setString(mensajeLlega);
    			
    			servicioCliente.append("\nMensaje de servidor:  "+mensajeLlega);
    			
    			
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		
    	}
    
    	public void run() {
    
    			StringBuffer url =	new StringBuffer("btspp://localhost:");
    			url.append(uuid.toString());
    			url.append(";name=Brailles");
    			conexion.append("\n"+url+"\n");
    			try {
    
    				StreamConnectionNotifier notifier = (StreamConnectionNotifier) Connector.open(url.toString());
    				//StreamConnectionNotifier connectionNotifier = (StreamConnectionNotifier) Connector.open(url);
    				
    				conexion.append("Servidor en marcha...");
    
    				while(true) {
    					try {
    						coneccion = (StreamConnection) notifier.acceptAndOpen();
    						in = coneccion.openDataInputStream();
    						out = coneccion.openDataOutputStream();
    						String texto = "Braille dice Hola!";
    						out.writeUTF(texto);
    						conexion.append("\n"+texto);
    						textoSer.setString(texto);
    						out.flush();
    						String mensajeLlega = in.readUTF();
    						conexion.append("\nMensaje Cliente:  "+mensajeLlega);
    					} catch(IOException e) {
    						e.printStackTrace();
    					}
    				}
    			} catch(IOException e) {
    
    				pantalla.setCurrent(new Alert("Error++: "+e));
    				alerta = new Alert("Error conexion",e.toString(),null, AlertType.ERROR);
    				pantalla.setCurrent(alerta);
    			}
    	
    		}
    	}
    each time i push the buton, it calls enviar()
    Last edited by oscarm; 2007-09-19 at 22:00.

  2. #2
    Regular Contributor
    Join Date
    Jul 2005
    Posts
    89

    Re: sending messages over bluetooth

    Sup oscarm,

    What API are you using?

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    31

    Re: sending messages over bluetooth

    Hi jinda007
    i'm using a S40's phone 3erd edition

    i have make some changes to aviod that the client phone don't freeze, but the message is not received, but when i prove in the WTK22 emulator it works.

    Code:
    	public void enviar() {
    		
    		new Thread(){
    			public void run() {
    				try {
    					coneccion =(StreamConnection) Connector.open(urlNaNe);
    					out = coneccion.openDataOutputStream();
    					out.writeUTF("Saludos desde el cliente!");
    					out.flush();						
    				} catch (IOException e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				}
    			}	
    		}.start();
    	}

Similar Threads

  1. Sending a bitmap image using bluetooth
    By ckt in forum Bluetooth Technology
    Replies: 1
    Last Post: 2006-12-07, 11:10
  2. Sending Text over bluetooth
    By Amilael in forum Symbian
    Replies: 1
    Last Post: 2006-08-11, 14:11
  3. Replies: 0
    Last Post: 2004-04-12, 12:22
  4. Replies: 0
    Last Post: 2004-04-12, 12:21
  5. Sending large data via Bluetooth sockets
    By yellow27 in forum Bluetooth Technology
    Replies: 0
    Last Post: 2003-12-18, 03:59

Posting Permissions

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