• หน้าแรก
  • หลักสูตร
  • บทความ
  • ร้านค้า
  • ติดต่อเรา
    มีคำถามเกี่ยวกับ odoo ?
    (02) 4302475
    info@odoothaidev.com
    Login
    Odoothaidev - We are Odoo professional in Thailand
    • หน้าแรก
    • หลักสูตร
    • บทความ
    • ร้านค้า
    • ติดต่อเรา

      JSON-RPC

      • บ้าน
      • บล็อก
      • JSON-RPC
      • JSON-RPC กับภาษา Python

      JSON-RPC กับภาษา Python

      • โพสโดย admin
      • หมวดหมู่ JSON-RPC
      • วันที่ กรกฎาคม 26, 2019
      • ความคิดเห็น 0 ความคิดเห็น
      • แท็ก JSON-RPC

      JSON-RPC กับภาษา Python

      สวัสดีผู้อ่านทุกท่านครับ บทความนี้ผมจะพาผู้อ่านไปใช้งาน JSON-RPC กับภาษา Python กันครับ

      JSON-RPC คืออะไร
      JSON-RPC เป็นมาตรฐานโปรโตคอลหนึ่งสำหรับใช้รับส่งข้อมูลผ่านเครือข่ายบนคอมพิวเตอร์ โดยนำ JSON มารวมกับ RPC (Remote procedure call) ปัจจุบันมาตรฐานล่าสุดของ JSON-RPC คือ JSON-RPC 2.0
      โดยมีการรับส่งข้อมูลดังนี้

      --> data sent to Server
      <-- data sent to Client

      อ่านรายละเอียด JSON-RPC เพื่มเติมได้ที่ www.jsonrpc.org

      ในการเขียนโปรแกรมภาษา Python ผมขอแนะนำโมดูล jsonrpclib ครับ

      โมดูล jsonrpclib เป็นโมดูลสำหรับใช้สร้าง JSON-RPC Server และ Client ในภาษา Python เนื่องจากโมดูล jsonrpclib ไม่ได้รับการพัฒนาต่อมานาน จึงได้มีคน fork โค้ดมาพัฒนาต่อในชื่อใหม่ว่า jsonrpclib-pelix ครับ

        • รองรับทั้ง JSON-RPC 1.0 และ JSON-RPC 2.0
        • ใช้ Apache License, Version 2.0
        • รองรับทั้ง Python 2 และ Python 3

      สามารถติดตั้งได้โดยใช้คำสั่ง pip:

      $ pip install jsonrpclib-pelix

      ตัวอย่างการใช้งาน
      สร้าง JSON-RPC Server

      [python]
      >>> from jsonrpclib.SimpleJSONRPCServer import SimpleJSONRPCServer
      >>>
      >>> server = SimpleJSONRPCServer((‘localhost’, 8080)) # ที่ตั้ง Server และ Port
      >>> server.register_function(pow)
      >>> server.register_function(lambda x,y: x+y, ‘add’)
      >>> server.register_function(lambda x: x, ‘ping’)
      >>> server.serve_forever()
      [/python]

      โค้ดส่วน Client

      [python]
      >>> import jsonrpclib
      >>> server = jsonrpclib.ServerProxy(‘http://localhost:8080’)
      >>> server.add(5,6)
      11
      >>> server.ping(6)
      6
      [/python]

      ข้อมูลที่รับส่งผ่าน JSON-RPC
      เนื่องจากโค้ดข้างบนเป็น JSON-RPC 2.0 จึงมีการรับส่งข้อมูลดังนี้

      --> {"jsonrpc": "2.0", "add": [5,6], "id": 1}
      <-- {"jsonrpc": "2.0", "result": 11, "id": 1}
      
      --> {"jsonrpc": "2.0", "ping": 6, "id": 2}
      <-- {"jsonrpc": "2.0", "result": 6, "id": 2}

      อ่านเอกสารเพิ่มเติมได้ที่ https://github.com/tcalmant/jsonrpclib
      ติดตามบทความต่อไปนะครับ
      ขอบคุณครับ

      https://python3.wannaphong.com/2015/05/json-rpc-python.html

      แท็ก:JSON-RPC

      • Share:
      อวตารของผู้เขียน
      admin

      โพสต์ก่อนหน้า

      เข้าใจ NodeJS ง่ายๆ สำหรับคนทำเว็บ
      กรกฎาคม 26, 2019

      โพสต์ถัดไป

      การพัฒนา API อย่างมืออาชีพ และทำไมต้อง RESTful Service
      กรกฎาคม 26, 2019

      ทิ้งคำตอบไว้

      อีเมลของคุณจะไม่แสดงให้คนอื่นเห็น ช่องข้อมูลจำเป็นถูกทำเครื่องหมาย *

      ค้นหาบทความ

      หมวดหมู่

      หมวดหมู่

      • Accounting
      • Adobe XD
      • API
      • Blog
      • Business
      • Buttons
      • CRM
      • Custom Fields
      • Design / Branding
      • Django
      • Ecommerce
      • ERP
      • ERP Flow
      • Express
      • Flectra
      • Form View
      • Frontend
      • Github
      • Github
      • Grant Chart
      • Header
      • iReport
      • Jasper Server & Server
      • Jaspersoft Studio
      • Java
      • JSON-RPC
      • Lazada
      • Linux
      • MLM
      • MRP
      • Nignx Proxy
      • NodeJS
      • Odoo 10
      • Odoo 12 Module
      • Odoo 13
      • Odoo 14 Development
      • Odoo 16
      • Odoo 8
      • Odoo 9
      • Odoo API
      • Odoo Certification
      • Odoo Developer
      • Odoo Ebook
      • Odoo Enterprise
      • Odoo ERP
      • Odoo Event
      • Odoo Implement
      • Odoo Inventory
      • Odoo Report
      • Odoo Security
      • Odoo V15
      • Open Source
      • Open-office
      • OpenERP 7.0
      • PhantomJS
      • Postgres SQL
      • Programming Language
      • Project Management
      • Python
      • Python3
      • Qweb
      • Reporting ระบบรายงาน
      • RML Report
      • Search View and Filters
      • Social Network
      • Statusbar
      • Ubuntu
      • Uncategorized
      • Voip & Call Center
      • Warehouse Management
      • WMS
      • Woocommerce
      • Workflow
      • XML-RPC
      • การ Implement
      • การเก็บข้อมูล Pre-Requirement
      • การเตรียมตัวเพื่อใช้งาน erp
      • ความรู้ด้านการตลาด CRM
      • ธีมเว็บไซต์ Odoo
      • ธุรกิจบริการ
      • ธุรกิจประเภทจัดอบรมสัมมนา
      • ธุรกิจสิ่งพิมพ์
      • นักพัฒนา
      • ประเภทธุรกิจที่เหมาะกับ Odoo
      • ระบบบัญชี
      • ระบบเคลม
      • ลิขสิทธิ์ – License
      Introduction LearnPress – LMS plugin

      Introduction LearnPress – LMS plugin

      Free
      From Zero to Hero with Nodejs

      From Zero to Hero with Nodejs

      Free
      Learn Python – Interactive Python

      Learn Python – Interactive Python

      $69.00

      บทความล่าสุด

      Securing Odoo logins with fail2ban
      22พ.ค.2023
      V16 Planned Date of Tasks are invisible.
      12ก.พ.2023
      Odoo Implement Methodology
      29พ.ย.2022
      (02) 430-2475
      info@odoothaidev.com
      Facebook Twitter Google-plus Pinterest

      Odoothaidev by OdooTeaM.

      • Privacy
      • Terms
      • Sitemap
      • Purchase

      เข้าสู่ระบบด้วยบัญชีเว็บไซต์ของคุณ

      ลืมรหัสผ่าน?

      Click to Copy