Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

G UI/umer udp module #69

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

nopunindented
Copy link

Following code for the UDPModule (after editing to shorten):

import threading
from threading import Thread

class UDPModule():
import socket
global udpsocket
udpsocket= socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
def init(self):
True

class ServerThread (Thread):
def init(self):
Thread.init(self)
def run(self):
Server().trysend()

class ClientThread (Thread):
def init(self):
Thread.init(self)
def run(self):
Client().tryreceive()

class Server():
def init(self):
True
def trysend(self):
localIP = "127.0.0.1"

    localPort = 20001

    bufferSize = 1024

    msgFromServer = "Hello UDP Client"

    bytesToSend = str.encode(msgFromServer)

    # Bind to address and ip

    udpsocket.bind((localIP, localPort))

    print("UDP server up and listening")

    # Listen for incoming datagrams

    while (True):
        bytesAddressPair = udpsocket.recvfrom(bufferSize)

        message = bytesAddressPair[0]

        address = bytesAddressPair[1]

        clientMsg = "Message from Client:{}".format(message)
        clientIP = "Client IP Address:{}".format(address)

        print(clientMsg)
        print(clientIP)

        # Sending a reply to client

        udpsocket.sendto(bytesToSend, address)

class Client():
def init(self):
True
def tryreceive(self):
msgFromClient = "Hello UDP Server"

    bytesToSend = str.encode(msgFromClient)

    serverAddressPort = ("127.0.0.1", 20001)

    bufferSize = 1024

    # Create a UDP socket at client side

    # Send to server using created UDP socket

    udpsocket.sendto(bytesToSend, serverAddressPort)

    msgFromServer = udpsocket.recvfrom(bufferSize)

    msg = "Message from Server {}".format(msgFromServer[0])

    print(msg)

New Threads

server = ServerThread()
client = ClientThread()

Start new Threads

server.start()
client.start()

nehalsekhon and others added 17 commits July 9, 2022 19:06
Created skeleton, need to add .qml widget, and work on state machine
	feat(GUI): Telemetry Models added
body
	reason for adding above models
	issue #4
feat(gui): command and subcommand classes
Added HealthCheckReq and HealthCheckModel. Connected click listeners to
command buttons in main2.py.

issue #4
…e Server/Client of the UDP communication method. A single socket is used in each class as well, and in addition to this, both the client and server can be ran simulatenously Issue#11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants