RPC and serialization

本文深入探讨了Socket(包括TCP和UDP)及远程过程调用(RPC)的基本原理和实现方式。详细介绍了Java中如何使用Socket建立服务器和客户端模型,以及UDP的低延迟特性。同时,解析了RPC如何在不同地址空间中执行程序,如同本地调用般简易。文章还涵盖了序列化过程,以及IDL文件在通讯协议中的作用。

Socket and RPC implement.

Implement can be seen there.

Socket

using TCP

  • TCP (Transmission Control Protocol) is a standard that defines how to establish and maintain a network conversation via which application programs can exchange data.

In Java

  • need java.net.Socket and java.net.ServerSocket
  • create Server and Client Models

Using UDP

  • UDP (User Datagram Protocol) is an alternative communications protocol to Transmission Control Protocol (TCP) used primarily for establishing low-latency and loss-tolerating connections between applications on the internet.

In Java

  • need java.net.*
  • using DatagramPacket and DatagramSocket

RPC

  • Remote Procedure Call,a pro
    • computer program causes a procedure (subroutine) to execute in a different address space (commonly on another computer on a shared network), which is coded as if it were a normal (local) procedure call, without the programmer explicitly coding the details for the remote interaction.
    • Procedure:Client
    • Callee procedure:Server
    • Function or Method:Service
  • call remote function (Method) Behavior like local call
  • 53727961116
  • How to call function using function name?

Server

  • need a thread of this method to wait for response from client(service)
  • need the class implement
  • need a interface to register this service

Client

  • need the interface of class needed
  • need a new Proxy Instance to proxy this method for client

Serialization

Serialization is the process of converting an object into a stream of bytes to store the object or transmit it to memory, a database, or a file.

module

  • IDL(Interface description language)文件
    • 参与通讯的各方需要对通讯的内容需要做相关的约定
  • IDL Compiler
    • 将IDL文件转换成各语言对应的动态库
  • Stub/Skeleton Lib
    • 负责序列化和反序列化的工作代码
  • Client/Server
    • 指的是应用层程序代码
  • 底层协议栈和互联网

Protocol

  • XML
  • JSON
  • Protobuf
  • Thrift
  • Avro

Reference

### Java RPC Frameworks Overview #### Introduction to Java RPC Frameworks Remote Procedure Call (RPC) frameworks allow developers to write programs that include subroutines or procedures which can be called from other locations through the network. In Java, several libraries provide robust support for implementing client-server architectures using this paradigm. One notable example is **kXML-RPC**, specifically designed for constrained environments like mobile phones running Java ME (J2ME). This framework leverages the kXML parser to offer an efficient way of performing remote procedure calls over HTTP while adhering to the XML-RPC specification[^3]. For more general-purpose applications developed under standard editions such as Java SE, there exist multiple alternatives including but not limited to: - **RMI (Remote Method Invocation)**: Built into core Java APIs since version 1.1. - **gRPC**: An open-source high-performance RPC framework developed by Google supporting various languages including Java. - **Apache Thrift**: A cross-platform service development tool offering code generation facilities across different programming languages enabling seamless communication between services written in diverse tech stacks. Each solution has its strengths depending upon specific project requirements ranging from performance considerations to ease-of-use aspects. ```java // Example gRPC server setup snippet in Java public class HelloWorldServer { public static void main(String[] args) throws IOException, InterruptedException { Server server = ServerBuilder.forPort(8080) .addService(new GreeterImpl()) .build() .start(); System.out.println("Server started"); server.awaitTermination(); } } ``` #### Characteristics and Use Cases When selecting a suitable RPC library for your application, factors such as serialization formats supported (e.g., JSON, Protocol Buffers), transport protocols available (HTTP/HTTPS vs custom transports), scalability potential alongside community backing should all play significant roles during evaluation processes. In addition to these technical attributes, it's also important to consider non-functional elements like licensing terms associated with each option before making final decisions regarding adoption within projects.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值