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

Client1:: Aim:-Write A Simple Dailyadvice Client-Server Code Using Java Socket Programming

The document provides code for a simple client-server application in Java using socket programming to exchange daily advice messages. The client code connects to the server, sends a request for advice, and prints the response. The server code listens for connections on port 1234, reads the client's request, prompts the user for a response, and writes the response back to the client.

Uploaded by

Sunny Sharma
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views2 pages

Client1:: Aim:-Write A Simple Dailyadvice Client-Server Code Using Java Socket Programming

The document provides code for a simple client-server application in Java using socket programming to exchange daily advice messages. The client code connects to the server, sends a request for advice, and prints the response. The server code listens for connections on port 1234, reads the client's request, prompts the user for a response, and writes the response back to the client.

Uploaded by

Sunny Sharma
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Aim:-Write a simple DailyAdvice client-server code using Java socket Programming.

Client1:
import java.io.*; import java.net.*; public class client1 { public static void main(String args[])throws Exception { String add=args[0]; int port=Integer.parseInt(args[1]); try { Socket socket=new Socket(add,port); System.out.println("successfully conneted"); BufferedReader r=new BufferedReader(new InputStreamReader(System.in)); DataOutputStream out = newDataOutputStream(socket.getOutputStream()); String st="write advice for client:"; out.writeUTF(st); DataInputStreamrecv=new DataInputStream(socket.getInputStream()); System.out.println(recv.readUTF()); } catch (IOException e) { e.printStackTrace(); } } }

Server1:
import java.io.*; import java.net.*; publicclass server1 { publicstaticvoid main(String args[])throws Exception { ServerSocketss=newServerSocket(1234); while(true) { Socket s=ss.accept(); DataInputStream in=newDataInputStream(s.getInputStream()); System.out.println(in.readUTF()); BufferedReader r=newBufferedReader(newInputStreamReader(System.in));

DataOutputStream out = newDataOutputStream(s.getOutputStream()); String st= r.readLine(); out.writeUTF(st); System.out.println(); } } }

Output:

You might also like