Preparation of electronic whiteboard software with Java

zhaozj2021-02-08  387

Modeling electronic whiteboard software with Java ---- With the rapid development of the Internet, while Email, WWW, FTP and other traditional non-real-time applications are increasingly mature, the demand for online real-time exchanges in real-time exchanges, such as online conferences, Distance teaching, collaborative work, etc. The application software in this area is also increasingly rich. This type of software is mainly divided into two categories, one is a pure text-type communication tool represented by the chat room on BBS and homepage; the other is the electronic whiteboard communication tool to be introduced herein. In addition to the full function of the chat room, the electronic whiteboard is more importantly, it has also introduced the drawing graphics exchange function, which has greatly strengthened the image and intuitiveness of online communication, and compensated for the shortcomings of writing. When the user distributed in different locations of the Internet communicates with a whiteboard, a person drawn on his own whiteboard can be displayed immediately on the whiteboard of others, as if everyone is painting on the same whiteboard, the distance between each other It is big to shorten. ---- Currently software with electronic whiteboard function has Microsoft's NetMeeting, etc. Such software needs to be installed with installation before use (Netmeeting is the options for InternetExplorer 4.0) and can be used after the setting is completed. In contrast, it is very advantageous to achieve a whiteboard function in the home page. Because it does not require the cumbersome steps of downloading, installation, and settings of traditional software, as long as you connect to the home page where you support Java's browser, you can use a whiteboard. The popularity of the browser (most common browsers support Java, such as InternetExPloer3.0 and NetscapeEnavigator 3.0 and above) make the potential customer base of this electronic whiteboard are huge. In addition, there is an obvious advantage of using Java to prepare electronic whiteboard software, which is the entire software (especially whiteboard servers), without re-modifying compilation, can run on the Java platform for NT, UNIX, Linux, etc. ---- Currently browser and Java-based electronic whiteboards are in its infancy, the author has not seen this type of software online. Due to the need, the author has developed a set of such electronic whiteboard software. Here I want to introduce some experience in the development to everyone to achieve the purpose of common communication. Working principle ---- Electronic whiteboard has two implementation models, one is a whiteboard server, so only two users are directly connected; the other is a whiteboard server, in principle, not limited to the number of people and chatting rooms Specific implementation of visual server performance and needs. This article is to introduce the latter. ---- When the user needs to communicate with others with a whiteboard, you need to connect to the home page where the applet is located, and the applet is running to the whiteboard server, and the server establishes TCP connections. Each user can draw graphics and input text on their own whiteboard (in the Applet screen), and the applet will send this information through the established network connection to the whiteboard server, and constantly listen, and receive graphics from the whiteboard server. Text messages, reappearing it now. The role of the whiteboard server is constantly listening, receiving information from each applet, and forwarding it to other users. ---- Since the browser restrictions on the Javapplet, the applet can only access the host host that sends the applet, so the whiteboard server can only be run on the host where the applet is located, allowing the applet to establish and remote whiteboard servers. Functional Design ---- A practical electronic whiteboard system should have the following basic functions:

When the user is browsing to the Whiteboard Home page, you can log in before you can communicate. This will provide the names used in communication, and you can do permission check if necessary. Users can choose to participate in and exit existing chat rooms according to the conversation topic of the chat room, and can build a new chat room. You can set some permissions based on the application field of the electronic whiteboard system. Users can only communicate with users in the same chat room. Information about a chat room is invisible for other talk rooms. The whiteboard should have at least some of the functions such as replacing the brush color, clear the drawing board (only on your own whiteboard). Whiteboard should have an operation prompt and operational information feedback bar, which displays some operations prompts and operation results information for the user, so that users can be used. Users should be able to suspend and restore their own whiteboard work. ---- In order to increase the practical value of the whiteboard, it is possible to consider an increase in the similar functions such as paintings like the Windows brush tool. This example is the establishment of the basic model of the electronic whiteboard, so these functions are not added. In fact, as long as you understand the design principles of the whiteboard communication protocol set to be introduced, it is very easy to increase the above functions. The formulation of the communication protocol set ---- Since the Java built-in standard basic communication protocol is TCP / IP, we only need to establish an electronic whiteboard application layer protocol set. The model of the protocol set will use the server / client request / response mode. The communication protocol set can be developed according to the required whiteboard function, and the protocol concentration includes login, graphical transmission (divided server issuance and client issuing two parts), text transmission (divided server issues and client issuing two parts), the server requires refreshing chamber List of members, clients require a list of conversations and members, join the designated conversation room, exit the chat room, establish a new conversation room, suspend / restore communication. ---- Since the TCP / IP protocol has been rely on the correctness of data transmission, the design of the communication protocol set in this electronic whiteboard should be as simple as possible, and the bandwidth utilization is improved. Details of the whiteboard communication protocol set can be referred to: ---- Note: (s) means that the part is issued by the server, the client is received; ---- (c) means that the part is issued by the client, the server is received; - Data format indicates that the quintet is indicated between the quotation marks, and the short arctive (2 bytes), (int) represents the standard plastic number (4 bytes).

Login (C): "Log" → User Name string. Graphics Transmission (Customer Send) (C): "DRAW" → (int) Color Value → (SHORT) Straight Line Start Sidal Sign → (SHORT) Linear Type Sidal Sign → (Short) Linear Time Y-axis. Graphics Transmission (SUP): "DRAW" → (int) color value → (short) line start point abscissa → (Short) line start point ordinate → (Short) line end point abscissa → (Short) line end point vertical coordinate. Text Transfer (Client Send) (C): "Text" → The user entered in the White Board Dialog box. Text Transfer (Server Send) (S): "Text" → Text Inputer Name String → The user entered the text string. Server requires refreshing chat room and member list (s): "refresh" → Talking room 1 Theme string → Trunk 1 Name string → Trunk 2 Name string → ... → " Complete "→ Talking Room 2 Strings → Trunk 2 User 1 Name Strings → Trunk 2 Name Strings → ... →" Complete "→ ... → Last Turban Theme Character String → User 1 Name string in the last conversation room → User 2 Name string → ... → "Complete" → "OK" in the last chat room. The client requires refreshing the chat room and member list (C): "refresh". (The server receives this command, the previous server is executed to refresh the chat room and the member list list, to join the specified chat room (C): "join" → apply for a response client request. Exit the chat room (C): "quit". Establish a new chat room (C): "new" → apply for new chat room theme string. (The server receives this command, which will automatically log out in the chat room of the user, and make the user become a new chat room) Suspend exchange (C): "Pause". Restore AC (C): "Continue". ---- The above-mentioned communication protocol set is followed by this electronic whiteboard software. This protocol set is very expandable and can expand the agreement set at any time by adding function. For example, it is necessary to transfer a circular pattern, and the protocol can be added to the protocol center: "Circle" → (int) color value → (Short) Ceremithic horizontal → (SHORT) Central ordinate → (SHORT) circular radius. Programming ---- Program Design Division Server JavaApplication and Client Javaapplets are done. ---- Need to pay attention to the following points in the programming:

Server programs do not build user threads when accessible, and quit the workflow of the thread when you quit the chat room. Because the thread operation mechanism of some operating systems is not sound enough, the thread is not fully released when the thread is destroyed, so that the system resources will be gradually consumed during the running of the whiteboard server. Therefore, all user service threads should be established in accordance with the maximum allowable number of users at the same time when the server is initialized. These threads will wait for the client to access, and the thread does not destroy when the user exits the chat room, but the user data is cleared, re-enter the waiting access state, ready to serve the next user. This ensures that the whiteboard server can run long-term reliably. When the user can generate a lot of graphic data when the user is continuously painted, the client applet is likely to use the task of transmitting these data to the server in the whiteboard's AWT event handler, it is likely to work due to the bottleneck of the network I / O. The AWT event handles threads are blocked, which affects the interface of the whiteboard Applet, browser, and other running applications. The solution is to enable the applet to build a background drawing data transmission thread. The AWT event handler of the whiteboard returns the user's drawing data to this thread through the pipe flow (PiPedStream), returns the network transmission to this thread. . In servers and client applets, the implementation of each sub-protocol must establish a synchronous block, and all operations of the sub-protocol are completed in this synchronization block to limit free access to network connections. Input stream and output flow. Make exclusion of these network resources when a thread performs a sub-protocol, and other threads cannot access these resources to ensure that the thread can perform sub-protocols accurately. However, since the synchronization operation reduces thread scheduling and execution efficiency, the scope of the synchronous code block is minimized as much as possible when ensuring the full execution of the child protocol. Since the data types in the protocol have both a string and an integrated number, DataInputStream and DataOutputStream are selected as the data input stream and output stream in the program. In addition, since the text of the UTF format supports the Chinese character set, it is convenient to read, so that the data read in the network communication in this program is all UTF format. When designing your own whiteboard program, you can switch to other text formats and coding rules as needed, but must ensure that the input stream and output stream use the same format and encoding. Considering the current NetScapenavigator 3.0 and InternetExplorer3.0 are still commonly used, both browser Java virtual machines do not support newer JDK1.1 standards, so JDK1 is not used in the client applet section of this program. 1 unique class library. ---- First introduce the preparation of the server program. It is necessary to determine several major classes and their members. The list is as follows: ---- Chat Server class: ---- The server program startup class. ---- Chat Server (): Create a server management interface. ---- INITSERVER (): Create a server junction, initialize the traffic chamber data, and establish multiple user service threads according to the maximum number of users allowed simultaneously. ---- Go (): Start the user service thread. ---- quit (): Turning the user service thread, turn off the server socket, and releases all resources. ---- User Class: Subcrete for the Thread class, implement user service threads, handling server / client opportunities. ---- Run (): Wait for the client to join; the client access is initialized, and enter the state of the loop listening to the client request, and call the corresponding protocol handler based on the client's request. ---- sendText (): According to the text transfer sub-protocol, receive the text information sent by the user and forward other users of the same chat room.

--- SendDraw (): According to the graphic transfer sub-protocol, receive graphical information sent by the user and forward other users of the same chat room. ---- CommandCenter (): Select the appropriate handler for the instructions received for the server. ---- Server_ask_refresh (): The server actively refreshes the chat room and member list. ---- Server_answer_resh (): Responding to the client requirements to refresh the chat room and member list. ---- Server_answer_log (): Respond to the client login. ---- Server_answer_join (): Responding to the user to join the specified conversation room request. ---- Server_answer_pause (): Responding to the user's suspension of exchange request. ---- Server_answer_continue (): Resumes the AC request. ---- Server_answer_newroom (): Responding to the user to establish a new chat room request. ---- Server_answer_quit (): Responding to the user withdraws from the chat request. ---- Server_ask_text (): The server forwards text information to the client. ---- Server_ask_draw (): The server forwards graphics information to the client. ---- refreshtoall (): The server refreshes all online client traffic chamber data. ---- RefreshtoAllNotme (): Server refreshes except for this user, all online client traffic compartment data. ---- SocketClose (): The user applies to exit, turn off the network socket, release the network resources occupied by the thread. ---- RoomGroup class: Save all conversation room data, direct processing and talk room. ---- NEWROOM (): Establish a new chat room. ---- Join (): Add to the designated conversation room. ---- Quit (): Exit the designated conversation room. ---- GetUsersName (): Returns the username of the specified interior. ---- GetroomID (): Inquiry and return to the chat room ID. ---- Room Category: Save and process user data of this chat room. ---- Join (): Join this chat room. ---- quit (): Exit this chat room. ---- GetUsersName (): Returns the username of this chat room. ---- DataBag class: packaging graphics and text data. ---- AboutDialog class: Generate the About dialog box to display copyright information. ---- Quitdialog class: Generate a QuitDialog dialog to confirm whether ending the server is running. ---- Client Applet The class and its main member functions are as follows: ---- ChatApplet class: The subclass of the Applet class implements the Runnable interface. ---- It is the core class of the whiteboard Applet, completes the task of communicating with the user. ---- Init (): Initialize the Applet user interface. ---- Run () :: Cycle Listening to the information from the whiteboard server, call the CommandCenter command handler. ---- Start (): Generates and launches the Applet thread. ---- stop (): Tone Applet threads.

---- DESTROY (): Abort the background graphics data transfer thread, call the shutdown network resource function. ---- SocketClose (): Turn off all open network sockets and traffic flows. ---- OpenSocket (): Establish network socket and communication flow. ---- CommandCenter (): Centralize to process commands from users and servers and from the application inside, call the corresponding handler. ---- Client_ask_refresh (): The client requests to refresh the traffic bank data. ---- Client_answer_refresh (): The client receives the traffic bank data sent by the server. ---- Client_ask_log (): Apply for login to the server. ---- Client_ask_join (): Apply to join the designated conversation room. ---- Client_ask_pause (): Suspension of communication. ---- Client_ask_continue (): Restore Communication. ---- Client_ask_newroom (): Apply for a new chat room. ---- Client_ask_quit (): Exit Talking Room. ---- Client_ask_text (): Sends the text information entered by the user. ---- Client_answer_text (): Receive text information of other users forwarded by the server. ---- Client_answer_draw (): Receive graphical information of other users forwarded by the server. ---- RefreshroomList (): Displays a list of conversations. ---- RefreshuserList (): Displays the list of users in the specified chat room. ---- PrintChat_area (): Displays the text of the user and other users from the server in the specified format in the Contributation Text box. ---- SendText (): Determines whether the text input is a valid string, if it is valid, call the send text function. ---- Drawboard_canvas (): Press the value of the DataBag object, draws on the whiteboard of the applet. ---- Boardcanvas_MouseDrag (): This function is called when the mouse is dragged on the whiteboard, and the mouse trajectory is packaged into a packet to send to the background network transmission thread. ---- logbutton_clicked (): This function is called when the user clicks the login button of the applet, and the network socket and the background network transmission thread are established. ---- Other Series User Interface Event Processing Functions: Communicate, receive user input, direct processing, or call the Commancy execute user command. ---- RoomData class: Store the subject of the chat room and the data class of the username ---- addUser (): Add username in this chat room. ---- REMOVEUSER (): Remove the username in this chat room. ---- GetUsersName (): Returns all usernames in this chat room. ---- Rooms class: Subclass for the VECTOR class. Store user data in all conversations.

---- GetroombyName (): Returns the RoomData object of the specified chat room by the topic of the Talk. ---- addelement (): Add a roomData object. ---- SendDrawData class: Subcale for the Thread class, implement the background network transmission thread. ---- Run (): The loop listens to graphics information from the Applet main thread and sends it to the server through the output stream generated through the network. ---- quit (): Close the connection stream of the thread and the Applet main thread. ---- LOGO class: subclass of the Canvas class. Used to display icons or copyright information in the applet. ---- In addition, several exception classes are also defined, which can make it easy for the program's exception handling mechanism to increase the maintenanceability and readability of the program. The default graphic file name of the Applet logo is "cdownlogo.jpg" (457 × 60), the default graphic file name of the server image is "icon.gif" (19 × 17). The port number of the server is 1000. The above can be modified as needed. Conclusion ---- This article combined with the author's programming experience introduced the programming process of browser and Java's electronic whiteboard software, hoping that these contents can be helpful to the majority of software developers. Welcome everyone with the author (lfl@cenpok.net), learn and communicate with some of the whiteboards. ---- Appendix Content: The complete source of the electronic whiteboard system. It has been tested, and it can be compiled directly. The home page demonstration embedded in the applet. Please note the parameter settings of the Applet in the home page. Introduction to the user interface and operation method of this electronic whiteboard client applet. ---- Appendix 1: Source Procedure: ---- Appendix 3: Electronic Whiteboard Client Instructions

Make sure the whiteboard server is running. Enable the browser to the home page where this applet is located. The following operations are on the Applet interface, please enter your username in the Username column, click the login button. Choose the chat room you are willing to join in the selection column of the chat room, the following current chat room users show existing users in the chat room you have selected. Click to join the chat room button to join the chat room. If you want to create a new chat room, enter the new theme in the new talk room topic column, click Create Talking Room button, and you automatically become a member of the chat room. After joining or created a chat room, you can talk and paint with users in the same chat room. Methods as below:

Click the color of the painting in the palette on the right side of the painting whiteboard. Picture of the mouse button on the painting whiteboard to drag the mouse. At the same time, other users in the chat room will automatically draw these graphics. Similarly, the graphics drawn by other users will also appear on your whiteboard. If you feel that the whiteboard is more chaotic, you can click to clear the whiteboard drawing button, and the whiteboard will automatically clear the screen. This operation does not affect the whiteboard of other users in the chat room. You can enter the other users in the same chat room in the text column of the homepage, press the Enter key or click the Send button to send to other users. All users entered in this chat room will appear in the text box below the whiteboard. Comprehensive use of paintings and conversations can be easily communicated with other users. After joining the chat room, click the Pause Talk button to temporarily stop talking to other users. Click this button again to resume it. Click to exit chat room buttons or leave the chat room home page will exit the chat room. If you need to enter the chat room again, please log in. Please pay attention to the system information box below the left under the home page, which will give some necessary operational tips. Author: Liu Feilong (Tsinghua University) Previous Next

转载请注明原文地址:https://www.9cbs.com/read-873.html

New Post(0)