Results 1 to 3 of 3
  1. #1
    dim_ath is offline Member
    Join Date
    Jan 2008
    Posts
    14
    Rep Power
    0

    Unhappy send/read int in a client/server app

    hi everyone!

    could you please tell me what methods to use in order the clients be able to
    send integers to server and server can read them?

    Thanks!

  2. #2
    roots's Avatar
    roots is offline Moderator
    Join Date
    Jan 2008
    Location
    Dallas
    Posts
    293
    Rep Power
    7

    Default

    Java 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.

  3. #3
    dim_ath is offline Member
    Join Date
    Jan 2008
    Posts
    14
    Rep Power
    0

Similar Threads

  1. send file via client - server model
    By spasavvas in forum Networking
    Replies: 15
    Last Post: 08-13-2010, 11:45 AM
  2. Server socket - send image to client
    By Hinty in forum Networking
    Replies: 2
    Last Post: 03-14-2009, 07:39 AM
  3. A Client to Send SMTP Mail
    By Java Tip in forum java.net
    Replies: 0
    Last Post: 04-07-2008, 08:06 PM
  4. how to send .jar files client to server
    By gobinathm in forum Networking
    Replies: 1
    Last Post: 12-25-2007, 04:05 AM
  5. Identify Client in Socket Client Server Application
    By masadjie in forum Networking
    Replies: 1
    Last Post: 12-20-2007, 09:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •