How to make simple python UDP socket server? - python

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

Related

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.

Build a Python UDP server

I have multiple clients which will send big data to a server. And I need build my server.
I want to use UDP as my server in python. There a key:
The server need know the data received is from where eg: client use
udp://ip:port/data?client=test as data put localtion. server know
this data is from test client
How I should build my server? Somebody can give advitise?
I think this should help you: https://wiki.python.org/moin/UdpCommunication#Receiving
But:
If considering extending this example for e.g. file transfers, keep in mind that UDP is not reliable. So you'll have to handle packets getting lost and packets arriving out of order. In effect, to get something reliable you'll need to implement something similar to TCP on top of UDP, and you might want to consider using TCP instead.

scapy for receiver?

I want to make a client-server model where server will send some UDP packet and client will receive them. I am thinking of using Scapy to send packets. Does Scapy gives any facility to receive packets(listen for packets)?
Scapy is able to craft packets, i.e. to build specific packets according to your needs. And yes, sending and receiving functions are the core functions of scapy. However, This is more for debugging purposes than for production systems. You should consider using Python's socket module directly.

How Get Message from TCP/IP Python?

how do I get the message that more than two messages in the buffer in the TCP / IP connection in python if I use the XML-RPC. I've tried using Cherrypy if the message is received by a normal state if more than one it will not get the message.
About the best answer you will get is to switch framework to twisted. Twisted makes networking laughable because of its simplicity
http://twistedmatrix.com/documents/current/web/howto/xmlrpc.html
Here is a tutorial for xml rpc using twisted.

stream socket send/receive broadcast messages?

I browsed the python socket docs and google for two days but I did not find any answer. Yeah I am a network programming newbie :)
I would like to implement some LAN chatting system with specific function for our needs. I am at the very beginning. I was able to implement a client-server model where the client connects to the server (socket.SOCK_STREAM) and they are able to change messages. I want to step forward. I want the client to discover the LAN with a broadcast how many other clients are available.
I failed. Is it possible that a socket.SOCK_STREAM type socket could not be used for this task?
If so, what are my opportunities? using udp packets? How I have to listen for brodcast messages/packets?
The broadcast is defined by the destination address.
For example if your own ip is 192.168.1.2, the broadcast address would be 192.168.1.255 (in most cases)
It is not related directly to python and will probably not be in its documentation. You are searching for network "general" knowledge, to a level much higher than sockets programming
*EDIT
Yes you are right, you cannot use SOCK_STREAM. SOCK_STREAM defines TCP communication. You should use UDP for broadcasting with socket.SOCK_DGRAM

Categories

Resources