letscheat1234

Network Prog Lab

Mar 1st, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. Network Programming
  2.  
  3. 1. Add 10 integers using TCP
  4.  
  5. Client :
  6.  
  7. import java.io.*;
  8. import java.util.*;
  9. import java.net.*;
  10.  
  11. class SumClient{
  12.         public static void main(String args[]) throws Exception{
  13.                 Socket sai = new Socket("localhost",7200);
  14.                 Scanner ul = new Scanner(System.in);
  15.                 DataOutputStream o = new DataOutputStream(sai.getOutputStream());
  16.                 for(int i=0;i<10;i++){
  17.                 String n = ul.nextLine();
  18.                 o.writeBytes(n+"\n");
  19.                 }
  20.         }
  21. }
  22.  
  23. Server :
  24.  
  25. import java.util.*;
  26. import java.io.*;
  27. import java.net.*;
  28.  
  29. class sai1{
  30.         public static void main(String args[]) throws Exception{
  31.                 ServerSocket s = new ServerSocket(7200);
  32.                 Socket sai = s.accept();
  33.                 int sohil=0;
  34.                 for(int i=0;i<10;i++){
  35.                 BufferedReader clinput = new BufferedReader(new InputStreamReader(sai.getInputStream()));
  36.                 sohil += Integer.parseInt(clinput.readLine());
  37.                 }
  38.                 System.out.println(sohil);
  39.         }
  40. }
Add Comment
Please, Sign In to add comment