Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Network Programming
- 1. Add 10 integers using TCP
- Client :
- import java.io.*;
- import java.util.*;
- import java.net.*;
- class SumClient{
- public static void main(String args[]) throws Exception{
- Socket sai = new Socket("localhost",7200);
- Scanner ul = new Scanner(System.in);
- DataOutputStream o = new DataOutputStream(sai.getOutputStream());
- for(int i=0;i<10;i++){
- String n = ul.nextLine();
- o.writeBytes(n+"\n");
- }
- }
- }
- Server :
- import java.util.*;
- import java.io.*;
- import java.net.*;
- class sai1{
- public static void main(String args[]) throws Exception{
- ServerSocket s = new ServerSocket(7200);
- Socket sai = s.accept();
- int sohil=0;
- for(int i=0;i<10;i++){
- BufferedReader clinput = new BufferedReader(new InputStreamReader(sai.getInputStream()));
- sohil += Integer.parseInt(clinput.readLine());
- }
- System.out.println(sohil);
- }
- }
Add Comment
Please, Sign In to add comment