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

Java Socket Client-Server Example

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)
41 views2 pages

Java Socket Client-Server Example

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

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

Client1:
import [Link].*; import [Link].*; public class client1 { public static void main(String args[])throws Exception { String add=args[0]; int port=[Link](args[1]); try { Socket socket=new Socket(add,port); [Link]("successfully conneted"); BufferedReader r=new BufferedReader(new InputStreamReader([Link])); DataOutputStream out = newDataOutputStream([Link]()); String st="write advice for client:"; [Link](st); DataInputStreamrecv=new DataInputStream([Link]()); [Link]([Link]()); } catch (IOException e) { [Link](); } } }

Server1:
import [Link].*; import [Link].*; publicclass server1 { publicstaticvoid main(String args[])throws Exception { ServerSocketss=newServerSocket(1234); while(true) { Socket s=[Link](); DataInputStream in=newDataInputStream([Link]()); [Link]([Link]()); BufferedReader r=newBufferedReader(newInputStreamReader([Link]));

DataOutputStream out = newDataOutputStream([Link]()); String st= [Link](); [Link](st); [Link](); } } }

Output:

You might also like