![]() We'll define the URL and API key, which the main class will hand off to a ChatBot class to do the real work. You can see the App.java main class in Listing 3. ![]() To begin, let’s frame a simple App.java main class that accepts input. Let’s define exactly what our ChatGPT application will do. We’ll keep things very basic for this demo. We want to accept an input string from the user and then output the AI’s response to it on the console. Mvn clean compile exec:java -Dexec.mainClass= From here on, we’ll use this command to run the application. You can test this out with the command in Listing 2, which currently outputs “Hello, World!” to the console. That will scaffold a new project in the /java-gpt directory. Before we continue, navigate to the /java-gpt/pom.xml file and set the Java compiler and source version to 11. Mvn archetype:generate -DgroupId=com.infoworld -DartifactId=java-gpt -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false -DarchetypeVersion=1.4 If this article proves to be any help, please let me know.Now let’s start creating a new Java application for this demo. We’ll use Maven from the command line. You can lay out a new project using the code in Listing 1. Implemented as good as I would have liked. The purpose of this project was to demonstrate Java sockets, so the whole History feature is not Source code is licensed under The Code Project Open License (CPOL). This is a class project which I wanted to share with others. For any browser to connect to a web-server, this server needs to have a global IP address so that it is visible on the Internet. Similarly jServer also is a application server and for chat over two different networks (say a campus LAN and DSL at your house), it also need to be run on a computer with a global IP address. To understand this, take the example of any web-server. Many people are confused why chat over different networks is not possible. The project's main purpose was to demonstrate networking concepts and due to deadline limitation it was not completed.Ģ. There was much confusion about two issues regarding the project. Upload upl = new Upload(addr, port, ui.file, ui) On sender side, start a new thread for file upload // Connect to the port specified in reply Reply to sender with IP address and port number Send( new Message( " upload_res", ui.username, dwn.port, msg.sender)) On recipient side, start a new thread for download Unlike messages, files do not go through jServer. The sender, on receiving positive reply connects to this socket and starts file uploadĪn advantage of this approach is that the clients can chat and transfer files at the same time.For positive reply, recipient's IP address and port number is sent back.If request is accepted then the recipient opens a new port.The recipient side sends its reply in a message of type upload_res.When a user wants to send a file, first his request is sent via a message of type upload_req. Arriving messages are then displayed on message board along with their senders. JMessenger first connects to the jServer, specified by its IP-address and port number. Find the thread of recipient and forward it to him In SocketServer process the messages based on their type public synchronized void handle( int ID, Message msg) Message msg = (Message) streamIn.readObject() In ServerThread read the incoming message and hand it to SocketServer Once the connection isĮstablished, ServerThread will listen for any messages and hand it over to SocketServer to process. The job of SocketServer is to wait for connections and for each connection start a new thread ServerThread. On startup the SocketServer runs inĪ separate thread. There are two main classes in jServer for handling connections and messages. Recipient: Username of recipient of the message.type: This can be set to message, login, newuser, etc.Message structureĮach message in jMessenger has four fields: ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |