kandi background
Explore Kits

ChernoChat | Cherno Chat project , as well as code | Socket library

 by   TheCherno Java Version: Current License: No License

 by   TheCherno Java Version: Current License: No License

Download this library from

kandi X-RAY | ChernoChat Summary

ChernoChat is a Java library typically used in Networking, Socket applications. ChernoChat has no bugs, it has no vulnerabilities and it has low support. However ChernoChat build file is not available. You can download it from GitHub.
All of the code for the Cherno Chat project, as well as the code for the individual episodes.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • ChernoChat has a low active ecosystem.
  • It has 70 star(s) with 77 fork(s). There are 60 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 1 open issues and 0 have been closed. On average issues are closed in 2349 days. There are 4 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of ChernoChat is current.
ChernoChat Support
Best in #Socket
Average in #Socket
ChernoChat Support
Best in #Socket
Average in #Socket

quality kandi Quality

  • ChernoChat has 0 bugs and 0 code smells.
ChernoChat Quality
Best in #Socket
Average in #Socket
ChernoChat Quality
Best in #Socket
Average in #Socket

securitySecurity

  • ChernoChat has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • ChernoChat code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
ChernoChat Security
Best in #Socket
Average in #Socket
ChernoChat Security
Best in #Socket
Average in #Socket

license License

  • ChernoChat does not have a standard license declared.
  • Check the repository for any license declaration and review the terms closely.
  • Without a license, all rights are reserved, and you cannot use the library in your applications.
ChernoChat License
Best in #Socket
Average in #Socket
ChernoChat License
Best in #Socket
Average in #Socket

buildReuse

  • ChernoChat releases are not available. You will need to build from source code and install.
  • ChernoChat has no build file. You will be need to create the build yourself to build the component from source.
  • It has 690 lines of code, 39 functions and 8 files.
  • It has medium code complexity. Code complexity directly impacts maintainability of the code.
ChernoChat Reuse
Best in #Socket
Average in #Socket
ChernoChat Reuse
Best in #Socket
Average in #Socket
Top functions reviewed by kandi - BETA

kandi has reviewed ChernoChat and discovered the below as its top functions. This is intended to give you an instant insight into ChernoChat implemented functionality, and help decide if they suit your requirements.

  • Create the main window .
    • Runs the server .
      • Manage all clients
        • Start listening to server
          • Open a datagram socket
            • Main entry point .
              • Close the connection
                • Create a client window .
                  • Get a unique identifier .
                    • Gets the ID .

                      Get all kandi verified functions for this library.

                      Get all kandi verified functions for this library.

                      ChernoChat Key Features

                      All of the code for the Cherno Chat project, as well as the code for the individual episodes.

                      ChernoChat Examples and Code Snippets

                      No Code Snippets are available at this moment for ChernoChat.

                      See all Code Snippets related to Socket

                      Community Discussions

                      Trending Discussions on ChernoChat
                      • How to release a mutex lock held by Thread which never lets it go, by continuously listening to a socket
                      Trending Discussions on ChernoChat

                      QUESTION

                      How to release a mutex lock held by Thread which never lets it go, by continuously listening to a socket

                      Asked 2021-Apr-05 at 12:59

                      There are two classes Client and ChatWindow, client has DatagramSocket, InetAddress and port fields along with methods for sending, receiving, and closing the socket. To close a socket I use an anonymous thread "socketCLOSE"

                      Client class

                      public class Client {
                      private static final long serialVersionUID = 1L;
                      
                      private DatagramSocket socket;
                      
                      private String name, address;
                      private int port;
                      private InetAddress ip;
                      private Thread send;
                      private int ID = -1;
                      
                      private boolean flag = false;
                      public Client(String name, String address, int port) {
                          this.name = name;
                          this.address = address;
                          this.port = port;
                      }
                      
                      
                      public String receive() {
                          byte[] data = new byte[1024];
                          DatagramPacket packet = new DatagramPacket(data, data.length);
                          try {
                              
                              socket.receive(packet);
                          
                          } catch (IOException e) {
                              e.printStackTrace();
                          }
                      
                          String message = new String(packet.getData());
                          return message;
                      }
                      
                      public void send(final byte[] data) {
                          send = new Thread("Send") {
                              public void run() {
                                  DatagramPacket packet = new DatagramPacket(data, data.length, ip, port);
                                  try {
                                      
                                      socket.send(packet);
                                      
                                  } catch (IOException e) {
                                      e.printStackTrace();
                                  }
                              }
                          };
                          send.start(); 
                      }
                      
                      public int close() {
                          System.err.println("close function called");
                           new Thread("socketClOSE") {
                              public void run() {
                                  synchronized (socket) {
                                      socket.close();
                                      System.err.println("is socket closed "+socket.isClosed());
                                     }
                              }
                          }.start(); 
                          
                          return 0;
                      }
                      

                      ChatWindow class is sort of a GUI which extends JPanel and implements Runnable, There are two threads inside the class - run and Listen.

                      public class ClientWindow extends JFrame implements Runnable {
                      private static final long serialVersionUID = 1L;
                      private Thread run, listen;
                      private Client client;
                      
                      private boolean running = false;
                      
                      public ClientWindow(String name, String address, int port) {
                          
                          client = new Client(name, address, port);
                          
                          createWindow();
                          console("Attempting a connection to " + address + ":" + port + ", user: " + name);
                          String connection = "/c/" + name + "/e/";
                          client.send(connection.getBytes());
                          
                          running = true;
                          run = new Thread(this, "Running");
                          run.start();
                      }
                      
                      private void createWindow() {
                                   
                                  {
                                   //Jcomponents and Layouts here
                                  }
                          
                          addWindowListener(new WindowAdapter() {
                              public void windowClosing(WindowEvent e) {
                                  String disconnect = "/d/" + client.getID() + "/e/";
                                  send(disconnect, false);
                                  running = false;
                                  client.close();
                                  dispose();
                              }
                          });
                      
                          setVisible(true);
                      
                          txtMessage.requestFocusInWindow();
                      }
                      
                      public void run() {
                          listen();
                      }
                      
                      private void send(String message, boolean text) {
                          if (message.equals("")) return;
                          if (text) {
                              message = client.getName() + ": " + message;
                              message = "/m/" + message + "/e/";
                              txtMessage.setText("");
                          }
                          client.send(message.getBytes());
                      }
                      
                      public void listen() {
                          listen = new Thread("Listen") {
                              public void run() {
                                  while (running) {
                                      String message = client.receive();
                                      if (message.startsWith("/c/")) {
                                          client.setID(Integer.parseInt(message.split("/c/|/e/")[1]));
                                          console("Successfully connected to server! ID: " + client.getID());
                                      } else if (message.startsWith("/m/")) {
                                          String text = message.substring(3);
                                          text = text.split("/e/")[0];
                                          console(text);
                                      } else if (message.startsWith("/i/")) {
                                          String text = "/i/" + client.getID() + "/e/";
                                          send(text, false);
                                      } else if (message.startsWith("/u/")) {
                                          String[] u = message.split("/u/|/n/|/e/");
                                          users.update(Arrays.copyOfRange(u, 1, u.length - 1));
                                      }
                                  }
                                  
                              }
                          };
                          listen.start();
                      }
                      
                      public void console(String message) {
                          }
                        }
                      

                      Whenever the client is closed, the client.close() is called which spawns socketCLOSE thread, but the thread does nothing, it enters the blocked state, as revealed by stack trace -

                      Name: socketClOSE State: BLOCKED on java.net.DatagramSocket@1de1602 owned by: Listen Total blocked: 1 Total waited: 0

                      Stack trace: app//com.server.Client$2.run(Client.java:90)

                      Name: Listen State: RUNNABLE Total blocked: 0 Total waited: 0

                      Stack trace:

                      java.base@14.0.1/java.net.DualStackPlainDatagramSocketImpl.socketReceiveOrPeekData(Native Method) java.base@14.0.1/java.net.DualStackPlainDatagramSocketImpl.receive0(DualStackPlainDatagramSocketImpl.java:130)

                      • locked java.net.DualStackPlainDatagramSocketImpl@3dd26cc7 java.base@14.0.1/java.net.AbstractPlainDatagramSocketImpl.receive(AbstractPlainDatagramSocketImpl.java:181)
                      • locked java.net.DualStackPlainDatagramSocketImpl@3dd26cc7 java.base@14.0.1/java.net.DatagramSocket.receive(DatagramSocket.java:864)
                      • locked java.net.DatagramPacket@6d21ecb
                      • locked java.net.DatagramSocket@1de1602 app//com.thecherno.chernochat.Client.receive(Client.java:59) app//com.thecherno.chernochat.ClientWindow$5.run(ClientWindow.java:183)

                      This doesn’t let SocketCLOSE thread close the socket inside the synchronized block as lock on socket is held by Listen thread. How can I make the listen thread release its lock, the program terminates without closing the socket and debugger shows Listen thread as still runnable. Is the implementation flawed itself or can this be solved ?

                      ANSWER

                      Answered 2021-Feb-24 at 14:08

                      I can reproduce the problem with JDK 14, but not with JDK 15 or newer.

                      This seems plausible, as JDK-8235674, JEP 373: Reimplement the Legacy DatagramSocket API indicates that the implementation has been rewritten for JDK 15. The report even says “The implementation also has several concurrency issues (e.g., with asynchronous close) that require an overhaul to address properly.

                      However, you can get rid of the problem with JDK 14 too; just remove the synchronized. Nothing in the documentation says that synchronization was required to call close() and when I removed it, my testcase worked as intended.

                      When you want to coordinate the multithreaded access to the socket of your application, you should use a different lock object than the socket instance itself.

                      Source https://stackoverflow.com/questions/66243966

                      Community Discussions, Code Snippets contain sources that include Stack Exchange Network

                      Vulnerabilities

                      No vulnerabilities reported

                      Install ChernoChat

                      You can download it from GitHub.
                      You can use ChernoChat like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the ChernoChat component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

                      Support

                      For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

                      DOWNLOAD this Library from

                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                      over 430 million Knowledge Items
                      Find more libraries
                      Reuse Solution Kits and Libraries Curated by Popular Use Cases
                      Explore Kits

                      Save this library and start creating your kit

                      Explore Related Topics

                      Share this Page

                      share link
                      Consider Popular Socket Libraries
                      Try Top Libraries by TheCherno
                      Compare Socket Libraries with Highest Support
                      Compare Socket Libraries with Highest Quality
                      Compare Socket Libraries with Highest Security
                      Compare Socket Libraries with Permissive License
                      Compare Socket Libraries with Highest Reuse
                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                      over 430 million Knowledge Items
                      Find more libraries
                      Reuse Solution Kits and Libraries Curated by Popular Use Cases
                      Explore Kits

                      Save this library and start creating your kit

                      • © 2022 Open Weaver Inc.