diff --git a/Client_Server_Chat_Room/build.xml b/Client_Server_Chat_Room/build.xml new file mode 100644 index 0000000..08129fb --- /dev/null +++ b/Client_Server_Chat_Room/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project Client_Server_Chat_Room. + + + diff --git a/Client_Server_Chat_Room/build/classes/client_server_chat_room/Chat_Server.class b/Client_Server_Chat_Room/build/classes/client_server_chat_room/Chat_Server.class new file mode 100644 index 0000000..d42728f Binary files /dev/null and b/Client_Server_Chat_Room/build/classes/client_server_chat_room/Chat_Server.class differ diff --git a/Client_Server_Chat_Room/build/classes/client_server_chat_room/Chat_client.class b/Client_Server_Chat_Room/build/classes/client_server_chat_room/Chat_client.class new file mode 100644 index 0000000..8741da8 Binary files /dev/null and b/Client_Server_Chat_Room/build/classes/client_server_chat_room/Chat_client.class differ diff --git a/Client_Server_Chat_Room/build/classes/client_server_chat_room/chat_Client_GUI$1.class b/Client_Server_Chat_Room/build/classes/client_server_chat_room/chat_Client_GUI$1.class new file mode 100644 index 0000000..8e376e9 Binary files /dev/null and b/Client_Server_Chat_Room/build/classes/client_server_chat_room/chat_Client_GUI$1.class differ diff --git a/Client_Server_Chat_Room/build/classes/client_server_chat_room/chat_Client_GUI$2.class b/Client_Server_Chat_Room/build/classes/client_server_chat_room/chat_Client_GUI$2.class new file mode 100644 index 0000000..b7bb42d Binary files /dev/null and b/Client_Server_Chat_Room/build/classes/client_server_chat_room/chat_Client_GUI$2.class differ diff --git a/Client_Server_Chat_Room/build/classes/client_server_chat_room/chat_Client_GUI$3.class b/Client_Server_Chat_Room/build/classes/client_server_chat_room/chat_Client_GUI$3.class new file mode 100644 index 0000000..fdafa28 Binary files /dev/null and b/Client_Server_Chat_Room/build/classes/client_server_chat_room/chat_Client_GUI$3.class differ diff --git a/Client_Server_Chat_Room/build/classes/client_server_chat_room/chat_Client_GUI$4.class b/Client_Server_Chat_Room/build/classes/client_server_chat_room/chat_Client_GUI$4.class new file mode 100644 index 0000000..250abdb Binary files /dev/null and b/Client_Server_Chat_Room/build/classes/client_server_chat_room/chat_Client_GUI$4.class differ diff --git a/Client_Server_Chat_Room/build/classes/client_server_chat_room/chat_Client_GUI$5.class b/Client_Server_Chat_Room/build/classes/client_server_chat_room/chat_Client_GUI$5.class new file mode 100644 index 0000000..0088f94 Binary files /dev/null and b/Client_Server_Chat_Room/build/classes/client_server_chat_room/chat_Client_GUI$5.class differ diff --git a/Client_Server_Chat_Room/build/classes/client_server_chat_room/chat_Client_GUI$6.class b/Client_Server_Chat_Room/build/classes/client_server_chat_room/chat_Client_GUI$6.class new file mode 100644 index 0000000..339f2f4 Binary files /dev/null and b/Client_Server_Chat_Room/build/classes/client_server_chat_room/chat_Client_GUI$6.class differ diff --git a/Client_Server_Chat_Room/build/classes/client_server_chat_room/chat_Client_GUI.class b/Client_Server_Chat_Room/build/classes/client_server_chat_room/chat_Client_GUI.class new file mode 100644 index 0000000..079de38 Binary files /dev/null and b/Client_Server_Chat_Room/build/classes/client_server_chat_room/chat_Client_GUI.class differ diff --git a/Client_Server_Chat_Room/build/classes/client_server_chat_room/chat_server_return.class b/Client_Server_Chat_Room/build/classes/client_server_chat_room/chat_server_return.class new file mode 100644 index 0000000..0d137f1 Binary files /dev/null and b/Client_Server_Chat_Room/build/classes/client_server_chat_room/chat_server_return.class differ diff --git a/Client_Server_Chat_Room/manifest.mf b/Client_Server_Chat_Room/manifest.mf new file mode 100644 index 0000000..1574df4 --- /dev/null +++ b/Client_Server_Chat_Room/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Client_Server_Chat_Room/nbproject/build-impl.xml b/Client_Server_Chat_Room/nbproject/build-impl.xml new file mode 100644 index 0000000..1f1d5cc --- /dev/null +++ b/Client_Server_Chat_Room/nbproject/build-impl.xml @@ -0,0 +1,1420 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Client_Server_Chat_Room/nbproject/genfiles.properties b/Client_Server_Chat_Room/nbproject/genfiles.properties new file mode 100644 index 0000000..ff32b0e --- /dev/null +++ b/Client_Server_Chat_Room/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=d351abdd +build.xml.script.CRC32=4ac8f005 +build.xml.stylesheet.CRC32=8064a381@1.80.1.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=d351abdd +nbproject/build-impl.xml.script.CRC32=9dcc86d0 +nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48 diff --git a/Client_Server_Chat_Room/nbproject/private/private.properties b/Client_Server_Chat_Room/nbproject/private/private.properties new file mode 100644 index 0000000..6fb1f4b --- /dev/null +++ b/Client_Server_Chat_Room/nbproject/private/private.properties @@ -0,0 +1,2 @@ +compile.on.save=true +user.properties.file=C:\\Users\\gogoh\\AppData\\Roaming\\NetBeans\\8.2\\build.properties diff --git a/Client_Server_Chat_Room/nbproject/private/private.xml b/Client_Server_Chat_Room/nbproject/private/private.xml new file mode 100644 index 0000000..64192cb --- /dev/null +++ b/Client_Server_Chat_Room/nbproject/private/private.xml @@ -0,0 +1,12 @@ + + + + + + file:/E:/project/git_hub/Client_Server_Chat_Room/src/client_server_chat_room/Chat_Server.java + file:/E:/project/git_hub/Client_Server_Chat_Room/src/client_server_chat_room/chat_server_return.java + file:/E:/project/git_hub/Client_Server_Chat_Room/src/client_server_chat_room/chat_Client_GUI.java + file:/E:/project/git_hub/Client_Server_Chat_Room/src/client_server_chat_room/Chat_client.java + + + diff --git a/Client_Server_Chat_Room/nbproject/project.properties b/Client_Server_Chat_Room/nbproject/project.properties new file mode 100644 index 0000000..4377ca5 --- /dev/null +++ b/Client_Server_Chat_Room/nbproject/project.properties @@ -0,0 +1,74 @@ +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.test.classpath=\ + ${run.test.classpath} +# 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}/Client_Server_Chat_Room.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.external.vm=true +javac.processorpath=\ + ${javac.classpath} +javac.source=1.8 +javac.target=1.8 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=client_server_chat_room.Client_Server_Chat_Room +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.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Client_Server_Chat_Room/nbproject/project.xml b/Client_Server_Chat_Room/nbproject/project.xml new file mode 100644 index 0000000..5da3311 --- /dev/null +++ b/Client_Server_Chat_Room/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + Client_Server_Chat_Room + + + + + + + + + diff --git a/Client_Server_Chat_Room/src/client_server_chat_room/Chat_Server.java b/Client_Server_Chat_Room/src/client_server_chat_room/Chat_Server.java new file mode 100644 index 0000000..5bfa98c --- /dev/null +++ b/Client_Server_Chat_Room/src/client_server_chat_room/Chat_Server.java @@ -0,0 +1,54 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package client_server_chat_room; +import java.io.*; +import java.net.*; +import java.util.ArrayList; +import java.util.Scanner; +/** + * + * @author gogoh + */ +public class Chat_Server { + public static ArrayListConnections=new ArrayList(); + public static ArrayList Current_users=new ArrayList(); + + + + public static void main(String[] args) throws Exception + { + try { + final int port=666; + ServerSocket Server=new ServerSocket(port); + System.out.println("waiting for clints....."); + while(true){ + Socket Sock= Server.accept(); + Connections.add(Sock); + System.out.println("client connected from: "+Sock.getLocalAddress().getHostName()); + Add_User_Name(Sock); + chat_server_return Chat= new chat_server_return(Sock); + Thread x=new Thread(Chat); + x.start(); + } + } catch (Exception e) { + System.out.print(e); + } + } + + private static void Add_User_Name(Socket Sock) throws Exception { + Scanner Input=new Scanner(Sock.getInputStream()); + String Username=Input.nextLine(); + Current_users.add(Username); + + for(int i=1;i<=Chat_Server.Connections.size();i++) + { + Socket temp_sock=(Socket)Chat_Server.Connections.get(i-1); + PrintWriter out =new PrintWriter(temp_sock.getOutputStream()); + out.println("#?!"+Current_users); + out.flush(); + } + } +} diff --git a/Client_Server_Chat_Room/src/client_server_chat_room/Chat_client.java b/Client_Server_Chat_Room/src/client_server_chat_room/Chat_client.java new file mode 100644 index 0000000..8454c2b --- /dev/null +++ b/Client_Server_Chat_Room/src/client_server_chat_room/Chat_client.java @@ -0,0 +1,91 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package client_server_chat_room; +import java.io.*; +import java.net.*; +import java.util.ArrayList; +import java.util.Scanner; +import javax.swing.JOptionPane; +/** + * + * @author gogoh + */ +public class Chat_client implements Runnable{ + Socket Sock; + Scanner in; + Scanner Send=new Scanner(System.in); + PrintWriter out; + + + public Chat_client(Socket Sock) { + this.Sock=Sock; + } + + + + + public void run(){ + + try { + try { + in=new Scanner(Sock.getInputStream()); + out=new PrintWriter(Sock.getOutputStream()); + out.flush(); + checkstream(); + + } + + finally { + Sock.close(); + } + + } catch (Exception e) { + System.out.println(e); + } + } + + private void checkstream() { + while (true) { + Receive(); + } + } + + private void Receive() { + if(in.hasNext()) + { + String message=in.nextLine(); + if(message.contains("#?!")) + { + String temp1=message.substring(3); + temp1=temp1.replace("[",""); + temp1=temp1.replace("]",""); + + String [] currentuser; + currentuser = temp1.split(", "); + chat_Client_GUI.jL_online.setListData(currentuser); +} + +else{ + chat_Client_GUI.TA_connversation.append(message+"\n"); + } + + } + } + public void send(String x) + { + out.println(chat_Client_GUI.username+": "+x); + out.flush(); + chat_Client_GUI.TF_message.setText(""); + } + public void disconnect() throws IOException + { + out.println(chat_Client_GUI.username+" has disconnected"); + out.flush(); + Sock.close(); + JOptionPane.showMessageDialog(null,"you disconnected"); + System.exit(0); + } +} diff --git a/Client_Server_Chat_Room/src/client_server_chat_room/chat_Client_GUI.java b/Client_Server_Chat_Room/src/client_server_chat_room/chat_Client_GUI.java new file mode 100644 index 0000000..2c5ec36 --- /dev/null +++ b/Client_Server_Chat_Room/src/client_server_chat_room/chat_Client_GUI.java @@ -0,0 +1,301 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package client_server_chat_room; + +import java.awt.event.ActionEvent; +import java.io.PrintWriter; +import java.net.Socket; +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.ScrollPaneConstants; +import javax.swing.SwingConstants; + +/** + * + * @author gogoh + */ +public class chat_Client_GUI { + public static Chat_client chatclient; + public static String username="Anonymous"; + + public static JFrame Mainwindow=new JFrame(); + private static JButton B_about=new JButton(); + private static JButton B_connect=new JButton(); + private static JButton B_disconnection=new JButton(); + private static JButton B_Help=new JButton(); + private static JButton B_send=new JButton(); + private static JLabel l_Message=new JLabel("Messasge:....."); + public static JTextField TF_message=new JTextField(); + private static JLabel L_conversation=new JLabel(); + public static JTextArea TA_connversation=new JTextArea(); + private static JScrollPane SP_converstion=new JScrollPane(); + private static JLabel L_online=new JLabel(); + public static JList jL_online=new JList(); + private static JLabel L_login=new JLabel(); + private static JLabel L_loginasbox=new JLabel(); + private static JScrollPane SP_online=new JScrollPane(); + + public static JFrame loginwindow=new JFrame(); + public static JTextField usernamebox=new JTextField(20); + private static JButton B_enter=new JButton("enter"); + private static JLabel L_enterusernmae=new JLabel("enter username: "); + private static JPanel p_login=new JPanel(); + + + public static void main(String args[]) + { + Build_main_window(); + initialize(); + } + public static void connect() + { + try { + final int port=666; + final String host="Galactica"; + Socket Sock=new Socket(host, port); + System.out.println("you connected to: " +host); + chatclient =new Chat_client(Sock); + + PrintWriter out=new PrintWriter(Sock.getOutputStream()); + out.println(username); + out.flush(); + + Thread x=new Thread(chatclient); + x.start(); + + } catch (Exception e) { + System.out.println(e); + JOptionPane.showMessageDialog(null,"server isnt responding.."); + System.exit(0); + } + + } + public static void initialize(){ + B_send.setEnabled(true); + B_disconnection.setEnabled(false); + B_connect.setEnabled(true); + } + private static void Build_main_window() { + Mainwindow.setTitle(username+"s chat"); + Mainwindow.setSize(450,500); + Mainwindow.setLocation(220,180); + Mainwindow.setResizable(false); + + config_main_window(); + main_window_action(); + + Mainwindow.setVisible(true); + + } + public static void Build_login_window() + { + loginwindow.setTitle("what is your name"); + loginwindow.setSize(400,100); + loginwindow.setLocation(250,200); + loginwindow.setResizable(false); + p_login=new JPanel(); + p_login.add(L_enterusernmae); + p_login.add(usernamebox); + p_login.add(B_enter); + loginwindow.add(p_login); + + login_action(); + loginwindow.setVisible(true); + + } + + private static void login_action() { + B_enter.addActionListener(new java.awt.event.ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + Action_B_enter(); + } + + private void Action_B_enter() { + if(!usernamebox.getText().equals("")) + { + username =usernamebox.getText().trim(); + L_loginasbox.setText(username); + Chat_Server.Current_users.add(username); + Mainwindow.setTitle(username +"s chat box"); + loginwindow.setVisible(false); + B_send.setEnabled(true); + B_disconnection.setEnabled(true); + B_connect.setEnabled(false); + connect(); + } + else + { + JOptionPane.showMessageDialog(null,"please enter your name: "); + } + } + }); + } + + + private static void config_main_window() { + Mainwindow.setBackground(new java.awt.Color(255,255,255)); + Mainwindow.setSize(500,320); + Mainwindow.getContentPane().setLayout(null); + + B_send.setForeground(new java.awt.Color(255,255,255)); + B_send.setBackground(new java.awt.Color(0,0,255)); + B_send.setText("SEND"); + Mainwindow.getContentPane().add(B_send); + B_send.setBounds(250,40,81,25); + + B_disconnection.setForeground(new java.awt.Color(255,255,255)); + B_disconnection.setBackground(new java.awt.Color(0,0,255)); + B_disconnection.setText("disconnect"); + Mainwindow.getContentPane().add(B_disconnection); + B_disconnection.setBounds(10,40,110,45); + + B_connect.setForeground(new java.awt.Color(0,0,255)); + B_connect.setBackground(new java.awt.Color(255,255,255)); + B_connect.setText("connect"); + Mainwindow.getContentPane().add(B_connect); + B_connect.setBounds(130,40,110,45); + + + B_Help.setForeground(new java.awt.Color(0,0,255)); + B_Help.setBackground(new java.awt.Color(255,255,255)); + B_Help.setText("help"); + Mainwindow.getContentPane().add(B_Help); + B_Help.setBounds(420,40,70,45); + + B_about.setForeground(new java.awt.Color(0,0,255)); + B_about.setBackground(new java.awt.Color(255,255,255)); + B_about.setText("about"); + Mainwindow.getContentPane().add(B_about); + B_about.setBounds(420,40,70,45); + + l_Message.setText("Message:...."); + Mainwindow.getContentPane().add(l_Message); + l_Message.setBounds(10,10,60,20); + + TF_message.setForeground(new java.awt.Color(0,0,255)); + TF_message.requestFocus(); + TF_message.setText("about"); + Mainwindow.getContentPane().add(TF_message); + TF_message.setBounds(70,4,260,30); + + L_conversation.setHorizontalAlignment(SwingConstants.CENTER); + L_conversation.setText("conversation"); + Mainwindow.getContentPane().add(L_conversation); + L_conversation.setBounds(100, 70, 140, 16); + + TA_connversation.setColumns(20); + TA_connversation.setFont(new java.awt.Font("Tahoma", 0, 12)); + TA_connversation.setForeground(new java.awt.Color(0,0,255)); + TA_connversation.setLineWrap(true); + TA_connversation.setRows(5); + TA_connversation.setEditable(false); + + //SP_converstion.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); + //SP_converstion.setHorizontalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); + SP_converstion.setViewportView(TA_connversation); + Mainwindow.getContentPane().add(SP_converstion); + SP_converstion.setBounds(10, 90, 330, 180); + + L_online.setHorizontalAlignment(SwingConstants.CENTER); + L_online.setText("curruntly online"); + L_online.setToolTipText(""); + Mainwindow.getContentPane().add(TF_message); + L_online.setBounds(350,70,130,16); + + String [] textname={"george","andrew","bavly","maria"}; + jL_online.setForeground(new java.awt.Color(0,0,255)); + jL_online.setListData(textname); + + //SP_online.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); + //SP_online.setHorizontalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); + SP_online.setViewportView(jL_online); + Mainwindow.getContentPane().add(SP_online); + SP_online.setBounds(350,90,130,180); + + L_login.setFont(new java.awt.Font("Tahoma", 0, 12)); + L_login.setText("currently logged in as: "); + Mainwindow.getContentPane().add(L_login); + L_online.setBounds(348,0,140,15); + + L_loginasbox.setHorizontalAlignment(SwingConstants.CENTER); + L_loginasbox.setFont(new java.awt.Font("Tahoma", 0, 12)); + L_loginasbox.setForeground(new java.awt.Color(255,0,0)); + L_loginasbox.setBorder(BorderFactory.createLineBorder(new java.awt.Color(0,0,255))); + Mainwindow.getContentPane().add(L_loginasbox); + L_loginasbox.setBounds(340,17,150,20); + + } + + private static void main_window_action() { + B_send.addActionListener(new java.awt.event.ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + Action_B_Send(); + } + + private void Action_B_Send() { + if(!TF_message.getText().equals("")) + { + chatclient.send(TF_message.getText()); + TF_message.requestFocus(); + } + } + }); + B_disconnection.addActionListener(new java.awt.event.ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + Action_B_disconnect(); + } + + private void Action_B_disconnect() { + try { + chatclient.disconnect(); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + B_connect.addActionListener(new java .awt.event.ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + Action_B_connect(); + } + + private void Action_B_connect() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + }); + B_about.addActionListener(new java .awt.event.ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + Action_B_about(); + } + + private void Action_B_about() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + }); + B_Help.addActionListener(new java .awt.event.ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + Action_B_help(); + } + + private void Action_B_help() { + JOptionPane.showMessageDialog(null,"multi-client chat george 2019 "); + } + }); + } +} \ No newline at end of file diff --git a/Client_Server_Chat_Room/src/client_server_chat_room/chat_server_return.java b/Client_Server_Chat_Room/src/client_server_chat_room/chat_server_return.java new file mode 100644 index 0000000..37ca131 --- /dev/null +++ b/Client_Server_Chat_Room/src/client_server_chat_room/chat_server_return.java @@ -0,0 +1,85 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package client_server_chat_room; +import com.sun.security.ntlm.Client; +import java.io.*; +import java.net.*; + +import java.net.Socket; +import java.util.Scanner; + +/** + * + * @author gogoh + */ +class chat_server_return implements Runnable{ + Socket Sock; + private Scanner in; + private PrintWriter out; + String message=""; + + chat_server_return(Socket x) { + this.Sock=x; + } + + public void CheckConn()throws IOException + { + if(!Sock.isConnected()){ + for(int i=0;i<=Chat_Server.Connections.size();i++) + { + if(Chat_Server.Connections.get(i)==Sock) + { + Chat_Server.Connections.remove(i); + } + } + for(int i=1;i<=Chat_Server.Connections.size();i++) + { + Socket temp_sock=(Socket)Chat_Server.Connections.get(i-1); + PrintWriter temp_out=new PrintWriter(Sock.getOutputStream()); + temp_out.println(temp_sock.getLocalAddress().getHostName()+"disconnected"); + temp_out.flush(); + System.out.println(temp_sock.getLocalAddress().getHostName()+"disconnected"); + } + } + } + + + @Override + public void run() { + try { + try { + in=new Scanner(Sock.getInputStream()); + out=new PrintWriter(Sock.getOutputStream()); + + while(true) + { + CheckConn(); + if(!in.hasNext()) + { + return; + } + message=in.nextLine(); + System.out.println("client said:" +message); + for(int i=1;i<=Chat_Server.Connections.size();i++) + { + Socket temp_sock=(Socket) Chat_Server.Connections.get(i-1); + PrintWriter temp_out=new PrintWriter(temp_sock.getOutputStream()); + temp_out.println(message); + temp_out.flush(); + System.out.println("sent to: "+temp_sock.getLocalAddress().getHostName()); + } + } + } + finally{ + Sock.close(); + } + } catch (Exception e) { + + System.out.println(e); + } + } + +} diff --git a/java-socket/README.md b/java-socket/README.md new file mode 100644 index 0000000..f1c3a11 --- /dev/null +++ b/java-socket/README.md @@ -0,0 +1 @@ +# java-socket diff --git a/java-socket/build.xml b/java-socket/build.xml new file mode 100644 index 0000000..a621987 --- /dev/null +++ b/java-socket/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project java_socket. + + + diff --git a/java-socket/build/classes/java_socket/Java_socket_server.class b/java-socket/build/classes/java_socket/Java_socket_server.class new file mode 100644 index 0000000..5f3b50a Binary files /dev/null and b/java-socket/build/classes/java_socket/Java_socket_server.class differ diff --git a/java-socket/build/classes/java_socket/java_socket_client.class b/java-socket/build/classes/java_socket/java_socket_client.class new file mode 100644 index 0000000..25481fa Binary files /dev/null and b/java-socket/build/classes/java_socket/java_socket_client.class differ diff --git a/java-socket/manifest.mf b/java-socket/manifest.mf new file mode 100644 index 0000000..1574df4 --- /dev/null +++ b/java-socket/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/java-socket/nbproject/build-impl.xml b/java-socket/nbproject/build-impl.xml new file mode 100644 index 0000000..11ddfd0 --- /dev/null +++ b/java-socket/nbproject/build-impl.xml @@ -0,0 +1,1420 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/java-socket/nbproject/genfiles.properties b/java-socket/nbproject/genfiles.properties new file mode 100644 index 0000000..b6bb08c --- /dev/null +++ b/java-socket/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=5c527137 +build.xml.script.CRC32=deb15b5d +build.xml.stylesheet.CRC32=8064a381@1.80.1.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=5c527137 +nbproject/build-impl.xml.script.CRC32=45b1e0bf +nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48 diff --git a/java-socket/nbproject/private/private.properties b/java-socket/nbproject/private/private.properties new file mode 100644 index 0000000..6fb1f4b --- /dev/null +++ b/java-socket/nbproject/private/private.properties @@ -0,0 +1,2 @@ +compile.on.save=true +user.properties.file=C:\\Users\\gogoh\\AppData\\Roaming\\NetBeans\\8.2\\build.properties diff --git a/java-socket/nbproject/project.properties b/java-socket/nbproject/project.properties new file mode 100644 index 0000000..e317904 --- /dev/null +++ b/java-socket/nbproject/project.properties @@ -0,0 +1,74 @@ +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.test.classpath=\ + ${run.test.classpath} +# 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}/java_socket.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.external.vm=true +javac.processorpath=\ + ${javac.classpath} +javac.source=1.8 +javac.target=1.8 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=java_socket.Java_socket_server +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.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/java-socket/nbproject/project.xml b/java-socket/nbproject/project.xml new file mode 100644 index 0000000..4ad9bdf --- /dev/null +++ b/java-socket/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + java_socket + + + + + + + + + diff --git a/java-socket/src/java_socket/Java_socket_server.java b/java-socket/src/java_socket/Java_socket_server.java new file mode 100644 index 0000000..dd1dbf3 --- /dev/null +++ b/java-socket/src/java_socket/Java_socket_server.java @@ -0,0 +1,36 @@ + +package java_socket; +import java.io.*; +import java.net.*; +/** + * + * @author gogoh + */ +public class Java_socket_server { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws Exception { + Java_socket_server Server=new Java_socket_server(); + Server.run(); + } + + private void run() throws Exception { + ServerSocket Servskt=new ServerSocket(666); + Socket Sock=Servskt.accept(); + InputStreamReader IR=new InputStreamReader(Sock.getInputStream()); //listen from the clint then put it in a bufferreader + BufferedReader BR=new BufferedReader(IR); + String Message=BR.readLine(); + System.out.println(Message); //print the clint message + + + if(Message !=null) + { + PrintStream PS= new PrintStream(Sock.getOutputStream()); + PS.println("Message recived successfully"); + + } + } + +} diff --git a/java-socket/src/java_socket/java_socket_client.java b/java-socket/src/java_socket/java_socket_client.java new file mode 100644 index 0000000..3e2f5e5 --- /dev/null +++ b/java-socket/src/java_socket/java_socket_client.java @@ -0,0 +1,27 @@ +package java_socket; + +import java.io.*; +import java.net.*; + +public class java_socket_client { + + public static void main(String[] args) throws Exception { + java_socket_client Client = new java_socket_client(); + Client.run(); + } + + private void run() throws Exception { + + Socket Sock = new Socket("localhost", 666); //the client should be having the port and the host address + //the socket is acting as the real socket or a connector each client is having his own socket + PrintStream PS = new PrintStream(Sock.getOutputStream()); //it is now sending to the server + PS.println("Hello to server from clint"); + + InputStreamReader IR = new InputStreamReader(Sock.getInputStream()); + BufferedReader BR = new BufferedReader(IR); + + String Message = BR.readLine(); + System.out.println(Message); + + } +}