WAY2JAVA
WAY2JAVA
WAY2JAVA
import java.io.*;
import java.net.*;
public class GossipClient
{
public static void main(String[] args) throws Exception
{
Socket sock = new Socket("127.0.0.1", 3000);
// reading from keyboard (keyRead object)
BufferedReader keyRead = new BufferedReader(new
InputStreamReader(System.in));
// sending to client (pwrite object)
OutputStream ostream = sock.getOutputStream();
PrintWriter pwrite = new PrintWriter(ostream, true);
import java.io.*;
import java.net.*;
public class GossipServer
{
public static void main(String[] args) throws Exception
{
ServerSocket sersock = new ServerSocket(3000);
System.out.println("Server ready for chatting");
Socket sock = sersock.accept( );
// reading from keyboard (keyRead object)
BufferedReader keyRead = new BufferedReader(new
InputStreamReader(System.in));
// sending to client (pwrite object)
OutputStream ostream = sock.getOutputStream();
PrintWriter pwrite = new PrintWriter(ostream, true);
pwrite.flush();
The flush() method of PrintStream class flushes any uncleared buffers
in memory. Generally when the streams are closed, the buffers are
pushed out of all the data contained in. But, in the program no stream
is closed; so, it is necessary to flush the data explicitly with flush()
method.
As you can observe, both programs are using same streams and
objects. The difference comes in while loop. Client sends first and then
receives where as server first receives and then sends. The other terms
of the code are explained in the earlier three applications.
Do you know?
1. A frame can be created without a border.
2. Coffee cup on the frame title bar can be changed with your photo.
3. Size of the button depends on the layout manager you choose.
4. The space along the border of the frame and components inside can
be adjusted.
5. Java support freelance drawing using AWT.
6. Components can be added without using layout manager.
7. Dialog box can be modal or modeless.
8. There exists HeadlessException in AWT.
9. You can draw a cube, cylinder etc. without having predefined
methods.
10. addActionListener() is a method of Button but not ActionListener.
11. Importing both java.awt and java.awt.event
IBM Storage Maintenance - OEM Level Expertise
Ad
cds.net
Accelerate
your
Mac
Install Fast &
Easy
MacKeeper Now
Get a
Faster Mac!
MacKeeper
URLConnection URL
LIKE US ON FACEBOOK
Way2Java
15,301 likes
Like Page
Contact Us
Be the first of your friends to like this