Socket programming is used for developing client-server applications in Java. In client-server architecture, the server provides some service and the client can use this service to get the desired output or result. Sockets also allow two or more computers to communicate with each other over the network using TCP/IP protocol.
Jayam ravi songs download. Rich in orchestration, ‘Senthoora’ is an extremely classy melody rendered by Luksimi Sivaneswaralingam in Thamarai’s lyrics.Watch the official song video here.To set this song as you’re CALLER TUNEFor Airtel - Dial 972For Vodafone - Dial For Idea - Dial 75For BSNL - Dial Song - SenthooraMovie - BoganSingers - Luksimi SivaneswaralingamLyrics - ThamaraiMusic - D. ImmanBagpipes-Lorne (UK)English Session Orchestra contracted by Dom Kelly Acoustic,Electric and Bass guitars-Keba Jeremiah, Chennai strings orchestra conducted by YensoneStarring - Jayam Ravi, Arvind Swami, Hansika MotwaniDirector - LakshmanProducer - Prabhu DevaBanner - Prabhu Deva StudiosMusic Label - Sony Music Entertainment India Pvt.
This course is for anyone who has basic knowledge about core Java concepts and who is totally new to Java socket programming. This course may not be suitable for students/programmers who are not familiar with Java.
This course is going to teach you how to write client-server applications in Java using socket programming. It will also teach you how to write a multi-user/group chat application in Java with chat logging functionality. All the concepts are explained in a very simple language. This course is highly practical-based with a very few power-point presentations. Apart from socket programming, this course also gives you a short introduction to some of the Java concepts which are required for understanding our chat application. This chat application will give you a concrete understanding of all socket programming fundamentals.
And finally, a chat application could be a good topic for your school/college mini-project. It is also an area which is quite unique to work on rather than regular Java projects. As it’s a short course, it wont be boring at all. You need to invest only around 2 hours of your time.
I believe you will enjoy this course and learn a lot. Xilisoft dvd ripper ultimate v6. Happy Coding :)
If you have a Java application that talks to a C application you need to send series of bytes and have both the sender and the receiver to agree on what these bytes represent. When talking between two Java applications, if both have access to the same code, I personally prefer to send Java Object between the two applications.
1. Overview of the Java Chat ApplicationThe Java Chat application you are going to build is a console application that is launched from the command line. The server and clients can run on different computers in the same network, e.g. Local Area Network (LAN).There can be multiple clients connect to a server and they can chat to each other, just like in a chat room where everyone can see other users’ messages. There’s no private chat between two users, for simplicity.After getting connected to the server, a user must provide his or her name to enter the chat. The server sends a list of currently online users to the new user.Every user is notified when a new user arrives and when a user has gone. Each message is prefixed with the username to keep track who sent the message.And finally, the user says ‘bye’ to quit the chat.The application consists of two parts: server and client. Each part can run independently on separate computers.Now, let’s see how to code this Java chat application in details.2. Create the Chat Server ProgramThe server is implemented by two classes: ChatServerand UserThread.The ChatServer class starts the server, listening on a specific port. When a new client gets connected, an instance of UserThread is created to serve that client. Since each connection is processed in a separate thread, the server is able to handle multiple clients at the same time.The following is source code of the ChatServer class:As you can see, theJava Chat Application Using SocketsChatServer class has two SetJava Socket Chatcollections to keep track the names and threads of the connected clients. Set is used because it doesn’t allow duplication and the order of elements does not matter:An important method in the ChatServer3. Create the Chat Client ProgramThe client is implemented by three classes: ChatClient, ReadThread and WriteThread.The ChatClient starts the client program, connects to a server specified by hostname/IP address and port number. Once the connection is made, it creates and starts two threads ReadThread and WriteThread.Here is source code of theChat Server In JavaChatClient class:The ReadThread is responsible for reading input from the server and printing it to the console repeatedly, until the client disconnects. This class is implemented as follows:And the WriteThread is responsible for reading input from the user and sending it to the server, continuously until the user types ‘bye’ to end the chat. This class is implemented as follows:The reasons for running these two threads simultaneously is that the reading operation always blocks the current thread (both reading user’s input from command line and reading server’s input via network). That means if the current thread is waiting for the user’s input, it can’t read input from the server.Therefore, two separate threads are used to make the client responsive: it can display messages from other users while reading message from the current user.That’s how the chat application is designed. For more details, you can read the comments in the source code provided. But there are no many comments because the code is self-explanatory.4. How to Run the Chat ServerYou need to specify the port number when running the server program from the command line. For example:This starts the server listening on the port number 8989, and you see the following output in the server once it started:The server is waiting for new clients forever, so you have to press Ctrl + C to terminate it.5. How to Run a Chat ClientTo run the client, you need to specify the server’s hostname/IP address and port number in the command line. For example:This tells the client to connect to the server at localhost on port 8989. Then you see the following message in the server’s console:And in the client’s console:You see, the server tells the client how many users are connected, but there’s no user at this time. Then the program asks for the username:Enter a username, say John, and then you can start chatting:Now, let’s start the second client with username is Peter. At this time, you see the server tells that there’s one online user is John:The user John is notified about new user Peter:Type some messages from John and Peter and you see each user sees other’s messages, just like talking in a chat room.Now, John wants to quit so he types ‘bye’- the client program terminates, and you see the following output in the server’s console:Peter also gets a message from the server:That’s basically how the chat application is running. You can test it with more clients and the application is still running smoothly. The following screenshot illustrates a test with 4 clients:Now, it’s your time to play around with this chat application with the source code attached.Related Java Network Tutorials:Java Chat Application Using RmiOther Java network tutorials:About the Author:Nam Ha Minh is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook.Java Chat Application Project Documentation
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |