0% found this document useful (0 votes)
4 views2 pages

Program 3-Network Connection

The document contains Java source code for a simple client-server application. The client connects to the server on port 6666 and sends a message 'Hello Server', while the server listens for connections, accepts them, and prints the received message. Both the client and server handle exceptions and close their connections properly.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Program 3-Network Connection

The document contains Java source code for a simple client-server application. The client connects to the server on port 6666 and sends a message 'Hello Server', while the server listens for connections, accepts them, and prints the received message. Both the client and server handle exceptions and close their connections properly.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Source Code : Client.

java
import [Link].*;
import [Link].*;
public class client {
public static void main(String[] args) {
try{
Socket s=new Socket("localhost", 6666);
DataOutputStream dout=new DataOutputStream([Link]());
[Link]("Hello Server");
[Link]();
[Link]();
[Link]();
}catch(Exception e) {[Link](e);}
}
}

Source Code : [Link]


import [Link].*;
import [Link].*;
public class myserver {
public static void main(String[] args){
try{
ServerSocket ss=new ServerSocket(6666);
Socket s=[Link]();//establishes connection
DataInputStream dis=new DataInputStream([Link]());
String str=(String)[Link]();
[Link]("message= "+str);
[Link]();
}catch(Exception e) { [Link](e);}
}
}
OUTPUT:

You might also like