SlideShare a Scribd company logo
4
Most read
5
Most read
10
Most read
Android Local Sockets In Native Code
T.V.R.Prasad
Contents
● Types of Sockets
● ANDROID_SOCKET_NAMESPACE_ABSTRACT
● ANDROID_SOCKET_NAMESPACE_RESERVED
● ANDROID_SOCKET_NAMESPACE_FILESYSTEM
Types Of Sockets
● ANDROID_SOCKET_NAMESPACE_ABSTRACT
A socket in the Linux abstract namespace.
● ANDROID_SOCKET_NAMESPACE_RESERVED
A socket in the Android reserved namespace in 
/dev/socket.  
● ANDROID_SOCKET_NAMESPACE_FILESYSTEM
A socket named with a normal filesystem path. 
● The code indicates the presence of filesystem 
entries for  the RESERVED and FILESYSTEM type of 
sockets. 
ANDROID_SOCKET_NAMESPACE_ABSTRACT
       /* Server Example */
int serverFd; /* File descriptor of Server Socket */
int clientFd;  /* File descriptor of Client Socket */
int clen; /* Size of the peer address */
serverFd = socket_local_server("android:debuggerd",
    ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM);   
 if(serverFd < 0) return ­1;
 struct sockaddr addr;
 socklen_t alen = sizeof(addr);
/* Wait for connection request from client */
    clientFd = accept(s, &addr, &alen);
/* Read and write data from client socket */
readLen = read(clientFd, data, dataLen);
writeLen = write(clientFd, status, sizeof(status));
ANDROID_SOCKET_NAMESPACE_ABSTRACT
                  /* Client Example */
int socketFd; /* File descriptor of Server Socket */
socketFd = socket_local_client("android:debuggerd",
    ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM);   
if(socketFd >= 0) {
/* Read and write data to the server */
readLen = read(socketFd, data, dataLen);
writeLen = write(socketFd, status, sizeof(status));
}
/*  Close the server socket once done */
close(socketFd);
ANDROID_SOCKET_NAMESPACE_RESERVED
     /* Server Example */
int serverFd; /* File descriptor of Server Socket */
int clientFd;  /* File descriptor of Client Socket */
int clen; /* Size of the peer address */
serverFd = socket_local_server("gps", 
ANDROID_SOCKET_NAMESPACE_RESERVED, SOCK_SEQPACKET);
/* Wait for connection request from client */
clientFd = accept(serverFd, 0, &clen); 
/* Read data from client socket */
readLen = read(clientFd, data, dataLen);
/* Write data to client socket */
writeLen = write(clientFd, status, sizeof(status));
ANDROID_SOCKET_NAMESPACE_RESERVED
/* Client Example */
int socketFd; /* File descriptor of Socket */
/*Create a client socket and connect to the address 
with the name gps in the reserved socket namespace */
socketFd = socket_local_client("gps", 
ANDROID_SOCKET_NAMESPACE_RESERVED, SOCK_SEQPACKET);
/*
socketFd less than 0 indicates failure to connect to 
the server,return Error;
*/
if(socketFd < 0) {
return Error;
} 
/* Read and write data to the server */
readLen = read(socketFd, data, dataLen);
writeLen = write(socketFd, status, sizeof(status));
ANDROID_SOCKET_NAMESPACE_FILESYSTEM
       /* Server Example */
/* File descriptor of Server Socket and Client sockets*/
int serverFd,clientFd; 
int connect(const char *name)
{
serverFd = socket_local_server(name, 
ANDROID_SOCKET_NAMESPACE_FILESYSTEM, SOCK_STREAM);
return serverFd;
}
/* Wait for connection request from client and after 
accepting the connection read and write data from 
client socket */
readLen = read(clientFd, data, dataLen);
ANDROID_SOCKET_NAMESPACE_FILESYSTEM
                  /* Client Example */
int socketFd; /* File descriptor of Server Socket */
int connect(const char *name)
{
socketFd = socket_local_client(name, 
ANDROID_SOCKET_NAMESPACE_FILESYSTEM, SOCK_STREAM);
return socketFd;
}
if(socketFd >= 0) {
/* Read and write data to the server */
readLen = read(socketFd, data, dataLen);
/*  Close the server socket once done */
close(socketFd);
Thank You

More Related Content

PDF
Android framework design and development
PDF
React Development with the MERN Stack
PPTX
Introduction Node.js
PPT
Jdbc complete
PDF
Embedded Android : System Development - Part IV (Android System Services)
PDF
Introduction to Node.js
PDF
Javascript Roadmap - The Basics
PDF
Android framework design and development
React Development with the MERN Stack
Introduction Node.js
Jdbc complete
Embedded Android : System Development - Part IV (Android System Services)
Introduction to Node.js
Javascript Roadmap - The Basics

What's hot (20)

PDF
Android : Architecture & Components
PPTX
Database in Android
PPTX
Backend Programming
PDF
Android Programming Basics
PDF
Embedded Android : System Development - Part II (HAL)
PPTX
Basic android-ppt
PPTX
webworkers
PDF
PowerShell UIAtomation
PPTX
Ppt android
PDF
Golang and Eco-System Introduction / Overview
PPTX
Java and XML
PPT
JavaScript Event Loop
PPTX
모두가 성장하는 스터디 만들기
PDF
Building beautiful apps with Google flutter
PPTX
0x003 - Exploiting LOLDrivers - Physical Memory Mayhem
PDF
Multimedia on android
PPT
Introduction to Eclipse IDE
PPT
Introduction to Android
PPTX
Coroutines talk ppt
Android : Architecture & Components
Database in Android
Backend Programming
Android Programming Basics
Embedded Android : System Development - Part II (HAL)
Basic android-ppt
webworkers
PowerShell UIAtomation
Ppt android
Golang and Eco-System Introduction / Overview
Java and XML
JavaScript Event Loop
모두가 성장하는 스터디 만들기
Building beautiful apps with Google flutter
0x003 - Exploiting LOLDrivers - Physical Memory Mayhem
Multimedia on android
Introduction to Eclipse IDE
Introduction to Android
Coroutines talk ppt
Ad

Similar to Android local sockets in native code (20)

PDF
PPTX
L5-Sockets.pptx
PPT
Sockets in unix
PDF
Java networking programs - theory
PPT
Sockets intro
PPT
Np unit2
PPT
Socket Programming
PPT
INTRODUCTION TO SOCKETS IN COMPUTER NETWORKS DEPT OF CSE.ppt
PPT
sockets_intro.ppt
PDF
PPTX
Lecture 1 Socket programming elementary tcp sockets.pptx
PDF
Socket Programming
PPT
03-socketprogramming for college students.ppt
PPT
03-socketprogrsamming forcoleeger students.ppt
PPT
Tcp sockets
PDF
Tcpsockets
PPT
Network programming-Network for engineering
PPT
Network Prog.ppt
PPT
Np unit iv ii
PPT
Sockets
L5-Sockets.pptx
Sockets in unix
Java networking programs - theory
Sockets intro
Np unit2
Socket Programming
INTRODUCTION TO SOCKETS IN COMPUTER NETWORKS DEPT OF CSE.ppt
sockets_intro.ppt
Lecture 1 Socket programming elementary tcp sockets.pptx
Socket Programming
03-socketprogramming for college students.ppt
03-socketprogrsamming forcoleeger students.ppt
Tcp sockets
Tcpsockets
Network programming-Network for engineering
Network Prog.ppt
Np unit iv ii
Sockets
Ad

Recently uploaded (20)

PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Digital Systems & Binary Numbers (comprehensive )
PPTX
Computer Software and OS of computer science of grade 11.pptx
PDF
medical staffing services at VALiNTRY
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Cost to Outsource Software Development in 2025
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
L1 - Introduction to python Backend.pptx
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
System and Network Administration Chapter 2
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Nekopoi APK 2025 free lastest update
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Digital Strategies for Manufacturing Companies
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
wealthsignaloriginal-com-DS-text-... (1).pdf
Odoo Companies in India – Driving Business Transformation.pdf
Wondershare Filmora 15 Crack With Activation Key [2025
PTS Company Brochure 2025 (1).pdf.......
Digital Systems & Binary Numbers (comprehensive )
Computer Software and OS of computer science of grade 11.pptx
medical staffing services at VALiNTRY
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Cost to Outsource Software Development in 2025
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
L1 - Introduction to python Backend.pptx
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
System and Network Administration Chapter 2
CHAPTER 2 - PM Management and IT Context
Nekopoi APK 2025 free lastest update
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Digital Strategies for Manufacturing Companies
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025

Android local sockets in native code