Skip to content
Snippets Groups Projects
Commit ede8fed5 authored by Zyad Alalgui's avatar Zyad Alalgui
Browse files

commit all

parents
No related branches found
No related tags found
No related merge requests found
{
"files.exclude": {
"**/.classpath": true,
"**/.project": true,
"**/.settings": true,
"**/.factorypath": true
},
"java.project.referencedLibraries": [
"lib/**/*.jar",
"c:\\Users\\hp\\Desktop\\mysql-connector-java-8.0.22\\mysql-connector-java-8.0.22.jar"
]
}
\ No newline at end of file
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
public class EchoServer extends Thread {
public static void main(String[] args) throws SocketException {
EchoServer echoServer = new EchoServer();
echoServer.run();
}
private DatagramSocket socket;
private boolean running;
private byte[] buf = new byte[2048];
public EchoServer() throws SocketException {
socket = new DatagramSocket(5005);
}
public void run() {
running = true;
dbConnect.editTable("DROP TABLE monitor");
while (running) {
DatagramPacket packet = new DatagramPacket(buf, buf.length);
try {
socket.receive(packet);
} catch (IOException e) {
e.printStackTrace();
}
InetAddress address = packet.getAddress();
int port = packet.getPort();
packet = new DatagramPacket(buf, buf.length, address, port);
String received = new String(packet.getData(), 0, packet.getLength());
if (received.equals("end")) {
running = false;
continue;
}
try {
String msg = new String(buf, 0, packet.getLength());
String insuline = msg.split(" ")[0].substring(0,6);
String hour = msg.split(" ")[1].substring(0,5);
String glycemy = msg.split(" ")[2].substring(0,6);
// dbConnect.tablesTable();
dbConnect.editTable("CREATE TABLE IF NOT EXISTS monitor (hour FLOAT,glycemy FLOAT, insuline FLOAT);");
System.out.println(" ");
System.out.println("Issued SQl query is: INSERT INTO monitor (hour, glycemy, insuline) VALUES ("+hour+","+glycemy+","+insuline+");");
dbConnect.editTable("INSERT INTO monitor (hour, glycemy, insuline) VALUES ("+hour+","+glycemy+","+insuline+");");
System.out.println("Patient glycemy is: "+glycemy+" mg/dL at "+hour+" hours. "+insuline+" units of insuline were injected in the last minute.");
socket.send(packet);
} catch (IOException e) {
e.printStackTrace();
}
}
socket.close();
}
}
\ No newline at end of file
File added
File added
File added
# Security holding package
This package name is not currently in use, but was formerly occupied
by another package. To avoid malicious use, npm is hanging on to the
package name, but loosely, and we'll probably give it to you if you
want it.
You may adopt this package by contacting support@npmjs.com and
requesting the name.
import socket
host = socket.gethostname()
port = 12345 # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
s.sendall(b'Hello, world')
data = s.recv(1024)
s.close()
print('Received', repr(data))
import socket
host = '104.199.43.195' # Symbolic name meaning all available interfaces
port = 12345 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, port))
print(host , port)
s.listen(1)
conn, addr = s.accept()
print('Connected by', addr)
while True:
try:
data = str(conn.recv(1024))
if not data: break
print ("Client Says: "+data)
conn.sendall("Server Says:hi")
except socket.error:
print("Error Occured.")
break
conn.close()
import socket
import sys
UDP_IP = "127.0.0.1"
UDP_PORT = 5005
socke = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
socke.bind((UDP_IP, UDP_PORT))
while True:
data, addr = socke.recvfrom(1024) # buffer size is 1024 bytes
print("received message: %s" % data)
HOST, PORT = "104.199.43.195", 80
dataToSend = data.join(sys.argv[1:])
# Create a socket (SOCK_STREAM means a TCP socket)
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
# Connect to server and send data
sock.connect((HOST, PORT))
sock.sendall(dataToSend + "c'est un test\n".encode("utf-8"))
# Receive data from the server and shut down
received = str(sock.recv(1024), "utf-8")
print("Sent: {}".format(dataToSend))
print("Received: {}".format(received))
{
"requires": true,
"lockfileVersion": 1,
"dependencies": {
"dgram": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/dgram/-/dgram-1.0.1.tgz",
"integrity": "sha1-N/OyAPgDOl/3WTAwicgc42G2UcM="
}
}
}
{
"_from": "dgram",
"_id": "dgram@1.0.1",
"_inBundle": false,
"_integrity": "sha1-N/OyAPgDOl/3WTAwicgc42G2UcM=",
"_location": "/dgram",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "dgram",
"name": "dgram",
"escapedName": "dgram",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "latest"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/dgram/-/dgram-1.0.1.tgz",
"_shasum": "37f3b200f8033a5ff759303089c81ce361b651c3",
"_spec": "dgram",
"_where": "C:\\Users\\hp\\Desktop\\CS Projects\\Info\\st5 ei",
"author": "",
"bugs": {
"url": "https://github.com/npm/security-holder/issues"
},
"bundleDependencies": false,
"deprecated": "npm is holding this package for security reasons. As it's a core Node module, we will not transfer it over to other users. You may safely remove the package from your dependencies.",
"description": "This package name is not currently in use, but was formerly occupied by another package. To avoid malicious use, npm is hanging on to the package name, but loosely, and we'll probably give it to you if you want it.",
"homepage": "https://github.com/npm/security-holder#readme",
"keywords": [],
"license": "ISC",
"main": "index.js",
"name": "dgram",
"repository": {
"type": "git",
"url": "git+https://github.com/npm/security-holder.git"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"version": "1.0.1"
}
const dgram = require('dgram');
const server = dgram.createSocket('udp4');
server.on('error', (err) => {
console.log(`server error:\n${err.stack}`);
server.close();
});
server.on('message', (msg, rinfo) => {
console.log(`server got: ${msg} from ${rinfo.address}:${rinfo.port}`);
});
server.on('listening', () => {
const address = server.address();
console.log(`server listening ${address.address}:${address.port}`);
});
server.bind(5005);
// Prints: server listening 0.0.0.0:41234
\ No newline at end of file
import socket
import sys
HOST, PORT = "104.199.43.195", 80
data = "test depuis Rennes".join(sys.argv[1:])
print(sys.argv)
# Create a socket (SOCK_STREAM means a TCP socket)
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
# Connect to server and send data
sock.connect((HOST, PORT))
sock.sendall(bytes(data + "\n", "utf-8"))
# Receive data from the server and shut down
received = str(sock.recv(1024), "utf-8")
print("Sent: {}".format(data))
print("Received: {}".format(received))
\ No newline at end of file
import java.sql.*;
import java.util.Enumeration;
import java.util.Vector;
import com.mysql.cj.protocol.Resultset;
public class dbConnect {
static String url = url = "jdbc:mysql://104.199.20.88:3306/testEwenZyad";
public void setUrl(String url){
this.url=url;
}
public static Connection connect(){
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(url ,"root", "gfh349.klm");
}
catch(Exception e){
System.err.println(e);
}
return conn;
}
public static void editTable(String query){
String sql = query;
try (Connection conn = connect(); Statement stmt = conn.createStatement()){
stmt.executeUpdate(sql);
}
catch (Exception e){
System.err.println(e);
}
}
public static void tablesTable(){
try (Connection conn = connect();)
{
//Retrieving the meta data object
DatabaseMetaData metaData = conn.getMetaData();
//Retrieving the columns in the database
ResultSet tables = metaData.getTables("testEwenZyad", null, null, null);
//Printing the column name and size
while (tables.next()) {
System.out.println("Table name: "+tables.getString("Table_NAME"));
System.out.println("Table catalog: "+tables.getString("TABLE_CAT"));
}
//Retrieving the columns in the database
ResultSet columns = metaData.getColumns("testEwenZyad", null, "test", null);
//Printing the column name and size
while (columns.next()) {
System.out.println("Column name: "+columns.getString("COLUMN_NAME"));
System.out.println(" ");
}
}
catch(Exception e){
System.err.println(e.getMessage());
}
}
public static void askTable(String query){
Vector<String[]> data = new Vector<String[]>();
String sql = query;
try (Connection conn = connect();
PreparedStatement stmt = conn.prepareStatement(sql))
{
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
String string1 =(rs.getString("hour"));
String string2 =(rs.getString("glycemy"));
String string3 =(rs.getString("insuline"));
System.out.println("hour: "+string1+" and glycemy: "+string2+" and insuline: "+string3);
}
}
catch(Exception e){
System.err.println(e.getMessage());
}
}
}
import java.util.Scanner;
import java.util.Vector;
public class init {
String url = "jdbc:mysql://104.199.20.88:3306/testEwenZyad";
public static void main(String args[]){
run();
}
public static void run(){
Scanner sc=new Scanner(System.in);
System.out.println("Entrez la query/l'edit destiné à la table");
String a = sc.nextLine();
// dbConnect.editTable(a);
dbConnect.askTable(a);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment