Category : tcp

This is the server.py module: def server(): host = socket.gethostname() port = 2252 server_socket = socket.socket() server_socket.bind((host, port)) server_socket.listen(2) conn, address = server_socket.accept() print("Connection from: " + str(address)) data1 = conn.recv(10).decode() data2 = conn.recv(10).decode() print("First number: " + data1) print("Second number: " + data2) conn.close() if __name__ == "__main__": server() This is the client.py module: ..

Read more

Is there a way to access a variable(name) from a different .py file (socket)? this is my client .py file. I have the user entering their name as a command-line argument. client.py argument I need in server # Check command line arguments to retrieve a URL. parser = argparse.ArgumentParser() parser.add_argument("name", help="name of client") parser.add_argument("address", help="the ..

Read more

this is a code for android package com.example.forcon; import androidx.appcompat.app.AppCompatActivity; import android.os.Handler; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.net.InetAddress; import java.net.Socket; public class MainActivity extends AppCompatActivity { private Handler mHandler; Socket socket; private String ip = ..

Read more

import RPi.GPIO as GPIO import dht11 import time import datetime GPIO.setwarnings(True) GPIO.setmode(GPIO.BCM) instance = dht11.DHT11(pin=18) import socket HOST = ‘192.168.35.129’ PORT = 9999 server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) server_socket.bind((HOST, PORT)) server_socket.listen() client_socket, addr = server_socket.accept() print(‘Connected by’, addr) try: while True: result = instance.read() if result.is_valid(): print("Last valid input: " + str(datetime.datetime.now())) print("Temperature: ..

Read more