View Single Post
  #2 (permalink)  
Old 01-03-2008, 02:21 PM
roots's Avatar
roots roots is offline
Moderator
 
Join Date: Jan 2008
Location: Dallas
Posts: 263
roots is on a distinguished road
Code:
package one; import java.io.DataInputStream; import java.net.ServerSocket; import java.net.Socket; public class Server { public static void main(String[] args) throws Exception{ ServerSocket serverSocket = new ServerSocket(8080); Socket socket = serverSocket.accept(); DataInputStream din = new DataInputStream(socket.getInputStream()); System.out.println(din.readInt()); socket.close() } } package one; import java.io.DataOutputStream; import java.net.Socket; public class Client { public static void main(String[] args) throws Exception { Socket socket = new Socket("localhost" , 8080 ); DataOutputStream out = new DataOutputStream(socket.getOutputStream()); out.writeInt(5); socket.close(); } }
Run one.Server first followed by one.Client should print 5.
__________________
dont worry newbie, we got you covered.
Reply With Quote