call a method from server

TreeChar

New Member
client1.java\[code\]import java.io.*;import java.net.*;class client1 { public static void main (String [] args) { Socket connectToServer; OutputStream out; BufferedReader in; String msg; String result; try { connectToServer = new Socket ("localhost", 5555); out = connectToServer.getOutputStream ( ); in = new BufferedReader (new InputStreamReader (connectToServer.getInputStream ( ))); msg = "sum" + "\n"; out.write (msg.getBytes ( ), 0, msg.length ( )); msg = "5" + "\n"; out.write (msg.getBytes ( ), 0, msg.length ( )); result = in.readLine ( ); System.out.println (result); connectToServer.close ( ); } catch (Exception ex) {System.out.println (ex);} }}\[/code\]server1.java\[code\]import java.io.*;import java.net.*;class server1 { public static void main (String [] args) { ServerSocket c; Socket cs; OutputStream out; BufferedReader in; String msg; String name; int parameter; int result=0; try { c = new ServerSocket (5555); cs = c.accept ( ); out = cs.getOutputStream ( ); in = new BufferedReader (new InputStreamReader (cs.getInputStream ( ))); name = in.readLine( ); parameter = Integer.parseInt (in.readLine ( )); result = name(parameter); out.write (result.getBytes ( ), 0, result.length ( )); } catch (Exception ex) {System.out.println (ex);} } static int sum (int n) { return (n + 5); }}\[/code\]I want to call a sum method from a server and I excepted from server to back the result of function but there are some bugs I'm really tired from it need some help my friends sorry for my bad English
 
Back
Top