diff --git a/ClientPersistente/.idea/.gitignore b/ClientPersistente/.idea/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/ClientPersistente/.idea/libraries/USocket.xml b/ClientPersistente/.idea/libraries/USocket.xml new file mode 100644 index 0000000..9657d41 --- /dev/null +++ b/ClientPersistente/.idea/libraries/USocket.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/ClientPersistente/.idea/libraries/org_netbeans_modules_java_j2seproject_copylibstask.xml b/ClientPersistente/.idea/libraries/org_netbeans_modules_java_j2seproject_copylibstask.xml new file mode 100644 index 0000000..89a05d8 --- /dev/null +++ b/ClientPersistente/.idea/libraries/org_netbeans_modules_java_j2seproject_copylibstask.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/ClientPersistente/.idea/misc.xml b/ClientPersistente/.idea/misc.xml new file mode 100644 index 0000000..639900d --- /dev/null +++ b/ClientPersistente/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ClientPersistente/.idea/modules.xml b/ClientPersistente/.idea/modules.xml new file mode 100644 index 0000000..9133bcd --- /dev/null +++ b/ClientPersistente/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/ClientPersistente/.idea/vcs.xml b/ClientPersistente/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/ClientPersistente/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ClientPersistente/.idea/workspace.xml b/ClientPersistente/.idea/workspace.xml new file mode 100644 index 0000000..b887a16 --- /dev/null +++ b/ClientPersistente/.idea/workspace.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + 1680682943510 + + + + + + \ No newline at end of file diff --git a/ClientPersistente/ClientPersistente.iml b/ClientPersistente/ClientPersistente.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/ClientPersistente/ClientPersistente.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/chifu/build.xml b/chifu/build.xml new file mode 100644 index 0000000..eb8cb7a --- /dev/null +++ b/chifu/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project chifu. + + + diff --git a/chifu/build/built-jar.properties b/chifu/build/built-jar.properties new file mode 100644 index 0000000..25423fa --- /dev/null +++ b/chifu/build/built-jar.properties @@ -0,0 +1,4 @@ +#Fri, 05 May 2023 12:43:45 +0200 + + +/home/docente/Scaricati/chifu= diff --git a/chifu/build/classes/.netbeans_automatic_build b/chifu/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/chifu/build/classes/.netbeans_update_resources b/chifu/build/classes/.netbeans_update_resources new file mode 100644 index 0000000..e69de29 diff --git a/chifu/build/classes/chefu/finestra$1.class b/chifu/build/classes/chefu/finestra$1.class new file mode 100644 index 0000000..8dd4a32 Binary files /dev/null and b/chifu/build/classes/chefu/finestra$1.class differ diff --git a/chifu/build/classes/chefu/finestra$2.class b/chifu/build/classes/chefu/finestra$2.class new file mode 100644 index 0000000..01a2fcc Binary files /dev/null and b/chifu/build/classes/chefu/finestra$2.class differ diff --git a/chifu/build/classes/chefu/finestra$3.class b/chifu/build/classes/chefu/finestra$3.class new file mode 100644 index 0000000..3996710 Binary files /dev/null and b/chifu/build/classes/chefu/finestra$3.class differ diff --git a/chifu/build/classes/chefu/finestra$4.class b/chifu/build/classes/chefu/finestra$4.class new file mode 100644 index 0000000..85c4f9d Binary files /dev/null and b/chifu/build/classes/chefu/finestra$4.class differ diff --git a/chifu/build/classes/chefu/finestra$5.class b/chifu/build/classes/chefu/finestra$5.class new file mode 100644 index 0000000..85644bc Binary files /dev/null and b/chifu/build/classes/chefu/finestra$5.class differ diff --git a/chifu/build/classes/chifu/ChiFu.class b/chifu/build/classes/chifu/ChiFu.class new file mode 100644 index 0000000..de8ce27 Binary files /dev/null and b/chifu/build/classes/chifu/ChiFu.class differ diff --git a/chifu/build/classes/chifu/Finestra$1.class b/chifu/build/classes/chifu/Finestra$1.class new file mode 100644 index 0000000..c901bd0 Binary files /dev/null and b/chifu/build/classes/chifu/Finestra$1.class differ diff --git a/chifu/build/classes/chifu/Finestra.class b/chifu/build/classes/chifu/Finestra.class new file mode 100644 index 0000000..3fcd63f Binary files /dev/null and b/chifu/build/classes/chifu/Finestra.class differ diff --git a/chifu/build/classes/chifu/Finestra.form b/chifu/build/classes/chifu/Finestra.form new file mode 100644 index 0000000..94e42eb --- /dev/null +++ b/chifu/build/classes/chifu/Finestra.form @@ -0,0 +1,82 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/chifu/build/classes/chifu/GestoreServer.class b/chifu/build/classes/chifu/GestoreServer.class new file mode 100644 index 0000000..da48442 Binary files /dev/null and b/chifu/build/classes/chifu/GestoreServer.class differ diff --git a/chifu/build/classes/chifu/Messaggio.class b/chifu/build/classes/chifu/Messaggio.class new file mode 100644 index 0000000..ac013bc Binary files /dev/null and b/chifu/build/classes/chifu/Messaggio.class differ diff --git a/chifu/dist/README.TXT b/chifu/dist/README.TXT new file mode 100644 index 0000000..4562026 --- /dev/null +++ b/chifu/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "chifu.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/chifu/dist/chifu.jar b/chifu/dist/chifu.jar new file mode 100644 index 0000000..7967751 Binary files /dev/null and b/chifu/dist/chifu.jar differ diff --git a/chifu/manifest.mf b/chifu/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/chifu/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/chifu/nbproject/build-impl.xml b/chifu/nbproject/build-impl.xml new file mode 100644 index 0000000..c4499dd --- /dev/null +++ b/chifu/nbproject/build-impl.xml @@ -0,0 +1,1771 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/chifu/nbproject/genfiles.properties b/chifu/nbproject/genfiles.properties new file mode 100644 index 0000000..76cbfa1 --- /dev/null +++ b/chifu/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=eb6d03b4 +build.xml.script.CRC32=18c3edea +build.xml.stylesheet.CRC32=f85dc8f2@1.101.0.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=eb6d03b4 +nbproject/build-impl.xml.script.CRC32=77cd96d8 +nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.101.0.48 diff --git a/chifu/nbproject/private/private.properties b/chifu/nbproject/private/private.properties new file mode 100644 index 0000000..e55d88f --- /dev/null +++ b/chifu/nbproject/private/private.properties @@ -0,0 +1,2 @@ +compile.on.save=true +user.properties.file=/home/docente/.netbeans/17/build.properties diff --git a/chifu/nbproject/private/private.xml b/chifu/nbproject/private/private.xml new file mode 100644 index 0000000..29bfac0 --- /dev/null +++ b/chifu/nbproject/private/private.xml @@ -0,0 +1,9 @@ + + + + + + file:/home/docente/Scaricati/chifu/src/chifu/CheFu.java + + + diff --git a/chifu/nbproject/project.properties b/chifu/nbproject/project.properties new file mode 100644 index 0000000..8a483c8 --- /dev/null +++ b/chifu/nbproject/project.properties @@ -0,0 +1,95 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processor.options= +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.modulepath=\ + ${run.modulepath} +debug.test.classpath=\ + ${run.test.classpath} +debug.test.modulepath=\ + ${run.test.modulepath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/chifu.jar +dist.javadoc.dir=${dist.dir}/javadoc +dist.jlink.dir=${dist.dir}/jlink +dist.jlink.output=${dist.jlink.dir}/chifu +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.external.vm=true +javac.modulepath= +javac.processormodulepath= +javac.processorpath=\ + ${javac.classpath} +javac.source=17 +javac.target=17 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.modulepath=\ + ${javac.modulepath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.html5=false +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +# The jlink additional root modules to resolve +jlink.additionalmodules= +# The jlink additional command line parameters +jlink.additionalparam= +jlink.launcher=true +jlink.launcher.name=chifu +main.class=chifu.ChiFu +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.modulepath=\ + ${javac.modulepath} +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +run.test.modulepath=\ + ${javac.test.modulepath} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/chifu/nbproject/project.xml b/chifu/nbproject/project.xml new file mode 100644 index 0000000..9899982 --- /dev/null +++ b/chifu/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + chifu + + + + + + + + + diff --git a/chifu/src/.DS_Store b/chifu/src/.DS_Store new file mode 100644 index 0000000..500ef19 Binary files /dev/null and b/chifu/src/.DS_Store differ diff --git a/chifu/src/chifu/ChiFu.java b/chifu/src/chifu/ChiFu.java new file mode 100644 index 0000000..f514caa --- /dev/null +++ b/chifu/src/chifu/ChiFu.java @@ -0,0 +1,10 @@ +package chifu; + +import javax.swing.JFrame; + +public class ChiFu { + public static void main(String[] args) { + JFrame gui = new Finestra(); + gui.setVisible(true); + } +} \ No newline at end of file diff --git a/chifu/src/chifu/Finestra.form b/chifu/src/chifu/Finestra.form new file mode 100644 index 0000000..94e42eb --- /dev/null +++ b/chifu/src/chifu/Finestra.form @@ -0,0 +1,82 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/chifu/src/chifu/Finestra.java b/chifu/src/chifu/Finestra.java new file mode 100644 index 0000000..876142a --- /dev/null +++ b/chifu/src/chifu/Finestra.java @@ -0,0 +1,112 @@ + +package chifu; + +import javax.swing.JOptionPane; + +public class Finestra extends javax.swing.JFrame { + + private boolean server_on; + + public Finestra() { + initComponents(); + server_on = false; + avviaLoop(); + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jScrollPane1 = new javax.swing.JScrollPane(); + jTextArea1 = new javax.swing.JTextArea(); + jTextField1 = new javax.swing.JTextField(); + jButton1 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + jTextArea1.setColumns(20); + jTextArea1.setRows(5); + jScrollPane1.setViewportView(jTextArea1); + + jButton1.setText("Invio"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1) + .addGroup(layout.createSequentialGroup() + .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 281, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(18, 18, 18) + .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 241, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jButton1)) + .addContainerGap()) + ); + + pack(); + }// //GEN-END:initComponents + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + try { + // TODO add your handling code here: + GestoreServer.scrivi(jTextField1.getText()); + } catch (Exception ex) { + JOptionPane.showMessageDialog(null, ex.toString()); + } + jTextField1.setText(""); + }//GEN-LAST:event_jButton1ActionPerformed + + private void avviaLoop() { + new Thread(() -> { + while(true) { + if(!server_on) { + System.out.println("Avvio il server"); + + server_on = true; + try + { + GestoreServer.messaggio = GestoreServer.ascolta(); + server_on = false; + System.out.println("ho ricevuto un qualcosa e dovrei avere un messaggio"); + jTextArea1.append(GestoreServer.messaggio.messaggio + "\n"); + GestoreServer.messaggio = null; + repaint(); + System.out.println("fine metodo"); + } catch (Exception ex) { + JOptionPane.showMessageDialog(null, ex.toString()); + } + } + } + }).start(); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTextArea jTextArea1; + private javax.swing.JTextField jTextField1; + // End of variables declaration//GEN-END:variables +} diff --git a/chifu/src/chifu/GestoreServer.java b/chifu/src/chifu/GestoreServer.java new file mode 100644 index 0000000..8b9b437 --- /dev/null +++ b/chifu/src/chifu/GestoreServer.java @@ -0,0 +1,54 @@ +package chifu; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.InetAddress; +import java.net.SocketException; +import java.net.UnknownHostException; + +public class GestoreServer { + private static int port = 50000; + private static int dim_buffer = 512; + private static String host = "172.16.127.255"; + public static Messaggio messaggio = null; + + public static Messaggio ascolta() throws SocketException, IOException, ClassNotFoundException { + Messaggio messaggio = null; + DatagramSocket server = new DatagramSocket(port); + byte[] buffer = new byte[dim_buffer]; + DatagramPacket pacchetto = new DatagramPacket(buffer, dim_buffer); + System.out.println("Datagram Server in ascolto"); + server.receive(pacchetto); + System.out.println("Ho ricevuto un messaggio da: " + + pacchetto.getAddress().getHostAddress()); + + messaggio = (Messaggio) new ObjectInputStream(new ByteArrayInputStream(pacchetto.getData())).readObject(); + + server.close(); + System.out.println("Server chiuso"); + + return messaggio; + } + + public static void scrivi(String testo) throws UnknownHostException, SocketException, IOException { + + Messaggio messaggio = new Messaggio(host, testo); + + InetAddress destinatario = InetAddress.getByName(host); + DatagramSocket client = new DatagramSocket(); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + new ObjectOutputStream(out).writeObject(messaggio); + byte[] flusso_messaggio = out.toByteArray(); + + DatagramPacket pacchetto = new DatagramPacket(flusso_messaggio, + flusso_messaggio.length, destinatario, port); + client.send(pacchetto); + client.close(); + } +} diff --git a/chifu/src/chifu/Messaggio.java b/chifu/src/chifu/Messaggio.java new file mode 100644 index 0000000..0f0f737 --- /dev/null +++ b/chifu/src/chifu/Messaggio.java @@ -0,0 +1,15 @@ +package chifu; + +import java.io.Serializable; + +public class Messaggio implements Serializable { + public String nome; + public String ip; + public String messaggio; + + public Messaggio(String ip, String messaggio) { + this.ip = ip; + this.nome = ip; + this.messaggio = messaggio; + } +}