SlideShare a Scribd company logo
1 of 3
Download to read offline
Felipe Ronchi Brigido

              Contato: lipaun@gmail.com



                           Comunicação Bluetooth entre
                                 Python / PyS60



              * PyBluez   ->   pybluez.googlecode.com

              * Socket (Pys60) -> www.mobilenin.com

              * LightBlue -> lightblue.sourceforge.net



              --> www.btessentials.com




**chat_cel.py**

    import socket
    import appuifw

   print 'Estabelecendo socket'
   sock = socket.socket(socket.AF_BT, socket.SOCK_STREAM)

   print 'Reservando porta'
   porta = socket.bt_rfcomm_get_available_server_channel(sock)
   sock.bind((quot;quot;, porta))
   sock.listen(1)

   print 'Estabelecendo servico'
   socket.bt_advertise_service(uquot;EXEMPLO PYCON 2008quot;, sock, True, socket.RFCOMM)

   print 'Aguardando conexao'
   conexao, endereco = sock.accept()

    print 'Conexao estabelecida com %s na porta %s'% (endereco, porta)

   print 'Iniciando chat!'
   conexao.send('Iniciando chat!')

    try:
           while True:
               msg = conexao.recv(1024)
               msg = unicode(msg)
               conexao.send(appuifw.query(msg, 'text', u''))

    except:
        pass

   socket.bt_advertise_service(uquot;EXEMPLO PYCON 2008quot;, sock, False, socket.RFCOMM)
   sock.close()
   conexao.close()
   print quot;Conexao finalizadaquot;
**chat_pc.py**

    import bluetooth

    # - Busca de dispositivos
    while True:
        print 'Buscando dispositivos'
        dispositivos = bluetooth.discover_devices(lookup_names = True)

           print 'Dipositivos encontrados:'
           for disp in dispositivos:
               print '%s | %s' % (dispositivos.index(disp), disp[1])

       num = raw_input('Digite o numero do dispositivo a conectar: ')
       try:
           num = int(num)
            break
       except:
            pass

   endereco = dispositivos[num][0]

    # - Busca de servicos
    while True:
        print 'Buscando servicos'
        servicos = bluetooth.find_service(address = endereco)

           print 'Servicos encontrados:'
           for servico in servicos:
               print '%s | %s - %s' % (servicos.index(servico), servico['port'], servico['name'])

       srv = raw_input('Digite o numero do servico a conectar: ')
       try:
           srv = int(srv)
            break
       except:
            pass

   porta = servicos[srv]['port']

   print 'Estabelecendo socket.'
   sock = bluetooth.BluetoothSocket( bluetooth.RFCOMM )

    print quot;Conectando a %s na porta %squot; % (endereco, porta)

   sock.connect((endereco, porta))

    try:
        while True:
            msg = raw_input(sock.recv(1024) + 'n>>> ')
             if msg == '': break
            sock.send(msg)
    except:
        pass

   sock.close()
   print quot;Conexao finalizadaquot;
**chat_cel_light.py**

    import lightblue
    import appuifw

   print 'Estabelecendo socket'
   sock = lightblue.socket()

   print 'Reservando porta'
   sock.bind(('', 0))
   sock.listen(1)

   print 'Establecendo servico'
   lightblue.advertise(quot;EXEMPLO PYCON 2008quot;, sock, lightblue.RFCOMM)

   print 'Aguardando conexao'
   conexao, endereco = sock.accept()

    print 'Conexao estabelecida com %s na porta %s'% (endereco[0], endereco[1])

   print 'Iniciando chat!'
   conexao.send('Iniciando chat!')

    try:
           while True:
               msg = conexao.recv(1024)
               msg = unicode(msg)
               conexao.send(appuifw.query(msg, 'text', u''))

    except:
        pass

   lightblue.stopadvertise(sock)
   sock.close()
   conexao.close()
   print quot;Conexao finalizadaquot;




**chat_pc_light.py**

    import lightblue

   print 'Buscando servico'
   servico = lightblue.selectservice()

   print 'Estebelecendo socket.'
   sock = lightblue.socket()

   print 'Conectando ao servico de %s' % servico[2]
   sock.connect((servico[0], servico[1]))

    try:
        while True:
            msg = raw_input(sock.recv(1024) + 'n>>> ')
             if msg == '': break
            sock.send(msg)
    except:
        pass

   sock.close()
   print quot;Conexao finalizadaquot;

More Related Content

Viewers also liked

Viewers also liked (20)

JGI Branding Strategy
JGI Branding StrategyJGI Branding Strategy
JGI Branding Strategy
 
PSP Tizianad
PSP TizianadPSP Tizianad
PSP Tizianad
 
iPhone 4 Bumper Conspiracy
iPhone 4 Bumper ConspiracyiPhone 4 Bumper Conspiracy
iPhone 4 Bumper Conspiracy
 
Psp Hong Davies
Psp Hong DaviesPsp Hong Davies
Psp Hong Davies
 
The Triangulation of Truth
The Triangulation of TruthThe Triangulation of Truth
The Triangulation of Truth
 
Ülesanne
ÜlesanneÜlesanne
Ülesanne
 
Prima vista 2012 kohta
Prima vista 2012 kohtaPrima vista 2012 kohta
Prima vista 2012 kohta
 
Chikasui
ChikasuiChikasui
Chikasui
 
This is binding - the idea
This is binding - the ideaThis is binding - the idea
This is binding - the idea
 
Gappei jokaso
Gappei jokasoGappei jokaso
Gappei jokaso
 
Students Comments Anna
Students Comments AnnaStudents Comments Anna
Students Comments Anna
 
Life Worlds
Life WorldsLife Worlds
Life Worlds
 
Beyond the Middle
Beyond the MiddleBeyond the Middle
Beyond the Middle
 
Evolution of ‘in store' - can bricks & mortar and e commerce work together ef...
Evolution of ‘in store' - can bricks & mortar and e commerce work together ef...Evolution of ‘in store' - can bricks & mortar and e commerce work together ef...
Evolution of ‘in store' - can bricks & mortar and e commerce work together ef...
 
Bersaing
BersaingBersaing
Bersaing
 
Social Games on Facebook: Worth it?
Social Games on Facebook: Worth it?Social Games on Facebook: Worth it?
Social Games on Facebook: Worth it?
 
Banking on the Millennial Experience
Banking on the Millennial ExperienceBanking on the Millennial Experience
Banking on the Millennial Experience
 
Odoo as your Enterprise Social Network
Odoo as your Enterprise Social NetworkOdoo as your Enterprise Social Network
Odoo as your Enterprise Social Network
 
The Three Sides to Engagement
The Three Sides to EngagementThe Three Sides to Engagement
The Three Sides to Engagement
 
ToolKit: Leveraging the at-purchase moment
ToolKit: Leveraging the at-purchase momentToolKit: Leveraging the at-purchase moment
ToolKit: Leveraging the at-purchase moment
 

Similar to Comunicação Bluetooth Entre Python e PyS60

python programming
python programmingpython programming
python programmingkeerthikaA8
 
Multi client
Multi clientMulti client
Multi clientganteng8
 
uygulamalarla siber güvenlik-siber guvenlik haftasi.pptx
uygulamalarla siber güvenlik-siber guvenlik haftasi.pptxuygulamalarla siber güvenlik-siber guvenlik haftasi.pptx
uygulamalarla siber güvenlik-siber guvenlik haftasi.pptxanilyelken
 
tp socket en C.pdf
tp socket en C.pdftp socket en C.pdf
tp socket en C.pdfYoussefJamma
 
为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?勇浩 赖
 
[4] 아두이노와 인터넷
[4] 아두이노와 인터넷[4] 아두이노와 인터넷
[4] 아두이노와 인터넷Chiwon Song
 
Udp socket programming(Florian)
Udp socket programming(Florian)Udp socket programming(Florian)
Udp socket programming(Florian)Flor Ian
 
MultiClient chatting berbasis gambar
MultiClient chatting berbasis gambarMultiClient chatting berbasis gambar
MultiClient chatting berbasis gambaryoyomay93
 
Socket programming
Socket programmingSocket programming
Socket programmingAnurag Tomar
 
Encrypt all transports
Encrypt all transportsEncrypt all transports
Encrypt all transportsEleanor McHugh
 
session6-Network Programming.pptx
session6-Network Programming.pptxsession6-Network Programming.pptx
session6-Network Programming.pptxSrinivasanG52
 
Multi client
Multi clientMulti client
Multi clientAisy Cuyy
 
INTRODUCTION TO SOCKETS IN COMPUTER NETWORKS DEPT OF CSE.ppt
INTRODUCTION TO SOCKETS IN COMPUTER NETWORKS DEPT OF CSE.pptINTRODUCTION TO SOCKETS IN COMPUTER NETWORKS DEPT OF CSE.ppt
INTRODUCTION TO SOCKETS IN COMPUTER NETWORKS DEPT OF CSE.pptsenthilnathans25
 
Computer Networks Lab File
Computer Networks Lab FileComputer Networks Lab File
Computer Networks Lab FileKandarp Tiwari
 
ZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleIan Barber
 
sms frame work
sms frame worksms frame work
sms frame workArulalan T
 

Similar to Comunicação Bluetooth Entre Python e PyS60 (20)

python programming
python programmingpython programming
python programming
 
Multi client
Multi clientMulti client
Multi client
 
UDP.yash
UDP.yashUDP.yash
UDP.yash
 
Introduction to asyncio
Introduction to asyncioIntroduction to asyncio
Introduction to asyncio
 
uygulamalarla siber güvenlik-siber guvenlik haftasi.pptx
uygulamalarla siber güvenlik-siber guvenlik haftasi.pptxuygulamalarla siber güvenlik-siber guvenlik haftasi.pptx
uygulamalarla siber güvenlik-siber guvenlik haftasi.pptx
 
tp socket en C.pdf
tp socket en C.pdftp socket en C.pdf
tp socket en C.pdf
 
为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?
 
[4] 아두이노와 인터넷
[4] 아두이노와 인터넷[4] 아두이노와 인터넷
[4] 아두이노와 인터넷
 
Udp socket programming(Florian)
Udp socket programming(Florian)Udp socket programming(Florian)
Udp socket programming(Florian)
 
MultiClient chatting berbasis gambar
MultiClient chatting berbasis gambarMultiClient chatting berbasis gambar
MultiClient chatting berbasis gambar
 
Socket programming
Socket programmingSocket programming
Socket programming
 
Encrypt all transports
Encrypt all transportsEncrypt all transports
Encrypt all transports
 
session6-Network Programming.pptx
session6-Network Programming.pptxsession6-Network Programming.pptx
session6-Network Programming.pptx
 
Multi client
Multi clientMulti client
Multi client
 
INTRODUCTION TO SOCKETS IN COMPUTER NETWORKS DEPT OF CSE.ppt
INTRODUCTION TO SOCKETS IN COMPUTER NETWORKS DEPT OF CSE.pptINTRODUCTION TO SOCKETS IN COMPUTER NETWORKS DEPT OF CSE.ppt
INTRODUCTION TO SOCKETS IN COMPUTER NETWORKS DEPT OF CSE.ppt
 
Computer Networks Lab File
Computer Networks Lab FileComputer Networks Lab File
Computer Networks Lab File
 
ZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made Simple
 
sockets_intro.ppt
sockets_intro.pptsockets_intro.ppt
sockets_intro.ppt
 
Sockets intro
Sockets introSockets intro
Sockets intro
 
sms frame work
sms frame worksms frame work
sms frame work
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

Comunicação Bluetooth Entre Python e PyS60

  • 1. Felipe Ronchi Brigido Contato: lipaun@gmail.com Comunicação Bluetooth entre Python / PyS60 * PyBluez -> pybluez.googlecode.com * Socket (Pys60) -> www.mobilenin.com * LightBlue -> lightblue.sourceforge.net --> www.btessentials.com **chat_cel.py** import socket import appuifw print 'Estabelecendo socket' sock = socket.socket(socket.AF_BT, socket.SOCK_STREAM) print 'Reservando porta' porta = socket.bt_rfcomm_get_available_server_channel(sock) sock.bind((quot;quot;, porta)) sock.listen(1) print 'Estabelecendo servico' socket.bt_advertise_service(uquot;EXEMPLO PYCON 2008quot;, sock, True, socket.RFCOMM) print 'Aguardando conexao' conexao, endereco = sock.accept() print 'Conexao estabelecida com %s na porta %s'% (endereco, porta) print 'Iniciando chat!' conexao.send('Iniciando chat!') try: while True: msg = conexao.recv(1024) msg = unicode(msg) conexao.send(appuifw.query(msg, 'text', u'')) except: pass socket.bt_advertise_service(uquot;EXEMPLO PYCON 2008quot;, sock, False, socket.RFCOMM) sock.close() conexao.close() print quot;Conexao finalizadaquot;
  • 2. **chat_pc.py** import bluetooth # - Busca de dispositivos while True: print 'Buscando dispositivos' dispositivos = bluetooth.discover_devices(lookup_names = True) print 'Dipositivos encontrados:' for disp in dispositivos: print '%s | %s' % (dispositivos.index(disp), disp[1]) num = raw_input('Digite o numero do dispositivo a conectar: ') try: num = int(num) break except: pass endereco = dispositivos[num][0] # - Busca de servicos while True: print 'Buscando servicos' servicos = bluetooth.find_service(address = endereco) print 'Servicos encontrados:' for servico in servicos: print '%s | %s - %s' % (servicos.index(servico), servico['port'], servico['name']) srv = raw_input('Digite o numero do servico a conectar: ') try: srv = int(srv) break except: pass porta = servicos[srv]['port'] print 'Estabelecendo socket.' sock = bluetooth.BluetoothSocket( bluetooth.RFCOMM ) print quot;Conectando a %s na porta %squot; % (endereco, porta) sock.connect((endereco, porta)) try: while True: msg = raw_input(sock.recv(1024) + 'n>>> ') if msg == '': break sock.send(msg) except: pass sock.close() print quot;Conexao finalizadaquot;
  • 3. **chat_cel_light.py** import lightblue import appuifw print 'Estabelecendo socket' sock = lightblue.socket() print 'Reservando porta' sock.bind(('', 0)) sock.listen(1) print 'Establecendo servico' lightblue.advertise(quot;EXEMPLO PYCON 2008quot;, sock, lightblue.RFCOMM) print 'Aguardando conexao' conexao, endereco = sock.accept() print 'Conexao estabelecida com %s na porta %s'% (endereco[0], endereco[1]) print 'Iniciando chat!' conexao.send('Iniciando chat!') try: while True: msg = conexao.recv(1024) msg = unicode(msg) conexao.send(appuifw.query(msg, 'text', u'')) except: pass lightblue.stopadvertise(sock) sock.close() conexao.close() print quot;Conexao finalizadaquot; **chat_pc_light.py** import lightblue print 'Buscando servico' servico = lightblue.selectservice() print 'Estebelecendo socket.' sock = lightblue.socket() print 'Conectando ao servico de %s' % servico[2] sock.connect((servico[0], servico[1])) try: while True: msg = raw_input(sock.recv(1024) + 'n>>> ') if msg == '': break sock.send(msg) except: pass sock.close() print quot;Conexao finalizadaquot;