gRPC server in Python with Unix domain socket - python

Will gRPC support in Python allow me to implement a server that listens on a Unix domain socket (as opposed to a port)? I am using Python 3.5.3 and grpcio/grpcio-tools 1.18.0.
So far, I have not been able to find any relevant example nor direct evidence. The official examples use server.add_insecure_port('[::]:50051'), and its not clear how a socket could fit there.

Apparently add_insecure_port(address) accepts Unix domain sockets in the format unix://var/run/test.sock after all.

Related

How to make simple python UDP socket server?

I am trying to make a python socket server based on UDP.
The point is that we need to receive data from the Java client socket server and the python UDP protocol socket server must throw JSON data to React in the front.
I have the level of knowledge to make a simple UDP chat server, so I'm worried a lot now.
I am currently reading the django channels official documentation.
Does django-channeles provide easy configuration to use UDP protocol as well?
There is a specification for raw UDP in the docs. UDP is not reliable as some of the data may be lost, so it is not widely used. If you must use it, you have to implement a UDP consumer based on the specification using the websocket consumers as a template

issue in sending realtime data from esp32 to Django webpage

I am having trouble in sending data from tcp client in my esp32 board to my python django server,I am not familiar with setting channels in Django ,is there a way so that i can send the data and display in my page?
in order for your microcontroller (esp32) communicate with your own server side code first you need to define protocol you're going to use:
A. TCP:
TCP relies on IP which provides address to communicate between computers. TCP/IP is a basis for internet and other networks.
B. HTTP:
HTTP mostly used by browser (IE, Google Chrome). It rides on top of TCP which provides a safe and reliable link between two computers because if packet get lost - it can be safely re-transmitted.
After deciding protocol that you're going to use now you need suitable server side code. In python there are several library / framework that you can use:
A. HTTP:
Django, Flask, AIOHTTP (all of this supports sending and receiving JSON (REST)), I preferably use one of this framework for my IoT Projects.
B. TCP: If your microcontroller is very minimal and doesn't support HTTP/JSON, you can use a simple SocketServer or Tornado TCP Server. Don't worry even though communication between your board and server done through TCP you can still import django's libraries and use django's ORM.

Inter-process communication between Python and Scala programs

I have a website that is backed by CherryPy web framework and a scala program that runs on a same machine and contains an actor system inside. OS is Ubuntu 12.04.
What I want is this: once user fills out and submits a form I send the data from CherryPy backend to scala program as a JSON string. How can this be done? What should I use in my python and scala programs to implement this functionality?
Instead of using raw sockets, you could consider a message broker like RabbitMQ. It supports both Scala and Python.
http://www.rabbitmq.com/tutorials/tutorial-one-python.html
On the Scala side, Akka has an AMQP module which abstracts AMQP Connection, Producer and Consumer as Actors.
http://doc.akka.io/docs/akka-modules/1.3.1/modules/amqp.html
As you are on a *nix system, you may want to look into Unix domain sockets (that link contains a very clear example use).
You can use the python socket module to easily create a Unix socket using:
import socket
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)

How Can Python Socket Programming be used to tranfer data in Shared Hosting?

I am creating an application that uses the IOT/IOE (Internet of things) to communicate with sensors.
For this I have used Python Socket programming to Code the Sockets that communicate and JavaScript for the user end Display.
I am curious as to how I can implement this on a shared Hosting server? I know it is possible in a Dedicated Server where i have all the permissions.
If it is possible to use the sockets in shared hosting , I also want to know how feasible it is to do so ?
Any guidance will be appreciated. Thanks
If it is possible to use the sockets in shared hosting , I also want
to know how feasible it is to do so ?
As long as your socket end point is reachable in the Internet, you should be able to create and reach a socket just like the case of dedicated server. Typically, you should be able to request a public IP address on the shared host. Other than Internet reachability, sockets are application-layer semantics and so you don't need any special features.

twisted - print IP datagrams from/to proxy

I have a twisted proxy from here: Python Twisted proxy - how to intercept packets .
It prints the HTTP data, and I would like also to intercept and examine the raw IP datgrams. How to hook the callback for the IP packets?
http://twistedmatrix.com/documents/11.0.0/api/twisted.pair.ip.IPProtocol.html
Twisted doesn't have a built-in friendly way to hook in a listener on a raw IP socket (SOCK_RAW). This is for several reasons:
using SOCK_RAW can be tricky and it can work in non-obvious ways;
in most environments, using such a socket requires elevated privileges;
and the packets you actually get through a raw socket differ a lot between operating systems (e.g., you won't get any raw TCP-protocol IP packets on *BSD/Darwin through a raw socket, even if you're root).
The best way to capture raw datagrams in general, in a remotely portable manner, is with libpcap. Here is a link to someone who appears to have combined pcap and Twisted in a reasonably intelligent way; that may help.
Twisted doesn't include comprehensive support for operating at the IP level. There is some support for parsing IP datagrams, as you found, but no built-in support for hooking into platform support for sending or receiving these.
You might want to take a look at scapy.

Categories

Resources