Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.net.*;
- import java.io.*;
- import java.util.Scanner;
- class MulClient
- {
- public static void main( String[] args )
- {
- Socket server = null;
- try
- {
- server = new Socket( "localhost", 3116 );
- Scanner in = new Scanner( server.getInputStream() );
- PrintWriter out = new PrintWriter( server.getOutputStream(), true );
- out.println( "2" );
- out.println( "4" );
- System.out.println( in.nextLine() );
- server = new Socket( "localhost", 3116 );
- in = new Scanner( server.getInputStream() );
- out = new PrintWriter( server.getOutputStream(), true );
- out.println( "23895737895" );
- out.println( "434589358935857" );
- System.out.println( in.nextLine() );
- }
- catch ( UnknownHostException e ) {
- e.printStackTrace();
- }
- catch ( IOException e ) {
- e.printStackTrace();
- }
- finally {
- if ( server != null )
- try { server.close(); } catch ( IOException e ) { }
- }
- }
- }
- import java.io.*;
- import java.math.BigInteger;
- import java.net.*;
- import java.util.Scanner;
- public class MulServer
- {
- private static void handleConnection( Socket client ) throws IOException
- {
- Scanner in = new Scanner( client.getInputStream() );
- PrintWriter out = new PrintWriter( client.getOutputStream(), true );
- String factor1 = in.nextLine();
- String factor2 = in.nextLine();
- out.println( new BigInteger(factor1).multiply( new BigInteger(factor2) ) );
- }
- public static void main( String[] args ) throws IOException
- {
- ServerSocket server = new ServerSocket( 3116 );
- while ( true )
- {
- Socket client = null;
- try
- {
- client = server.accept();
- handleConnection ( client );
- }
- catch ( IOException e ) {
- e.printStackTrace();
- }
- finally {
- if ( client != null )
- try { client.close(); } catch ( IOException e ) { }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment