Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Java Network Utilization

Options
  • 26-05-2006 2:33am
    #1
    Closed Accounts Posts: 2,653 ✭✭✭


    I've been working on a server/client program in java, it's pretty small and basic, I'm new to java networking but basically I set up within the server an array of sockets, an array of objectinputstreams and an array of objectoutputstreams, so each client (typically around 8 of them) has one of each.

    So, ten times per second, the server needs to send each client one object via its objectoutputstream, the object consists of around 2 dozen integers(it can vary), then receives one object back from each client via its object inputstream(an object consisting of precisely 3 integers)

    Using localhost as the connect address I've happily had one server and multiple clients all running on one machine at full speed, and indeed beyond it if I remove my framerate limiter.

    However, once I actually try to network, even one client connecting to the server across a 100Mbit LAN, the program crawls along. And I know it's not sending enough data to be pushing the bandwidth available. Indeed, looking at task manager on both machines shows a network utilisation of 0.1% while the program runs.

    So is there something I'm missing or doing wrong? The program should clearly be able to run at full speed if it was utilising the bandwidth available, so why isn't it? I've tried it in multiple scenarios and running it over wireless or even across the internet doesn't actually seem to be a whole lot slower than running it over wired LAN, so where am I going wrong?


Comments

  • Closed Accounts Posts: 261 ✭✭bishopLEN


    Could you post the code snippets that you think are the culprits please.


  • Closed Accounts Posts: 2,653 ✭✭✭steviec


    bishopLEN wrote:
    Could you post the code snippets that you think are the culprits please.
    bishopLEN wrote:
    Could you post the code snippets that you think are the culprits please.

    Right the networking parts of my code are...
    In Server.java(setting up server socket, accepting clients, and then the main program loop:
    				in = new ObjectInputStream [numClients];
    				out = new ObjectOutputStream [numClients];
    				socks = new Socket [numClients];
    				try 
    				{
    					sock = new ServerSocket(5678);
    				}
    
    ..............
    
    				for(int i = 0; i<socks.length; i++)
    				{
    					infoLabel.setText("Waiting for " + (socks.length - i) + " clients.");
    					socks[i] = sock.accept(); 
    				}
    				for(int i = 0; i<socks.length; i++)
    				{
    					in[i] = new ObjectInputStream(socks[i].getInputStream());
    					out[i] = new ObjectOutputStream(socks[i].getOutputStream());
    				}  
    
    ..................
    
    while(playing)
    			{
    				for(int i = 0; i<socks.length; i++)
    				{
    					try
    					{
    						Match temp = new Match(matchx);
    						out[i].writeObject(temp);
    					}
    					catch(Exception e){}
    				}   
    				for(int i = 0; i<socks.length; i++)
    				{
    					try
    					{
    						orders[i] = (Command) in[i].readObject();
    					}
    					catch(Exception e){}
    				}  
    				matchx.calc(orders);
    			}
    
    

    And in Client:
    					sock = new Socket(address, 5678);
    					out = new ObjectOutputStream(sock.getOutputStream());
    					in = new ObjectInputStream(sock.getInputStream());
    
    
    ........
    
    
    		while(!finished)
    		{
    			try
    			{
    				matchx = (Match) in.readObject();
    				out.writeObject(c);
    				updateBots();		
    			}
    			catch(Exception e)
    			{
    				finished = true;
    			}
    		}
    

    Thats the networking part of the code, I've cut out a lot of lines that are irrelevant


  • Closed Accounts Posts: 4,943 ✭✭✭Mutant_Fruit


    Is it because your network IO isn't asynchronous? I don't know really, i'm just throwing out ideas.


Advertisement