Page 1 of 2 12 LastLast
Results 1 to 20 of 21
  1. #1
    Daslee's Avatar
    Daslee is offline Member
    Join Date
    Mar 2012
    Location
    Plunge, Lithuania
    Posts
    36
    Rep Power
    0

    Default My ip lags, localhost does not

    Hello. Why my sockets game are lagging if Im connecting like this: ip:2002? But if I connecting like this: localhost:2002 it doesn't lag..
    Last edited by Daslee; 04-09-2012 at 12:08 AM.

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

    Default Re: My ip lags, localhost does not

    I'd suspect because the remote IP is just that: remote, most likely going through your ISP. Localhost is not.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: My ip lags, localhost does not

    Moved from New to Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    Daslee's Avatar
    Daslee is offline Member
    Join Date
    Mar 2012
    Location
    Plunge, Lithuania
    Posts
    36
    Rep Power
    0

    Default Re: My ip lags, localhost does not

    Quote Originally Posted by doWhile View Post
    I'd suspect because the remote IP is just that: remote, most likely going through your ISP. Localhost is not.
    Is there are any way to avoid going through ISP? Maybe i should connect my internet without router?

  5. #5
    Diargg is offline Senior Member
    Join Date
    Feb 2012
    Posts
    117
    Rep Power
    0

    Default Re: My ip lags, localhost does not

    Unless you are implementing local network (ie your friend's computer is on the same network as you), you will encounter lag. Even if you are on a local network, you'll still encounter (minor) lag.

  6. #6
    Daslee's Avatar
    Daslee is offline Member
    Join Date
    Mar 2012
    Location
    Plunge, Lithuania
    Posts
    36
    Rep Power
    0

    Default Re: My ip lags, localhost does not

    But thats only for my sockets server/client. If i run Lineage 2, Counter-Strike server, other peoples can play in my server without any lag cuz my internet is fast. And also Lineage 2 Server is same on Java as my game, just difference that my server uses ~1mb space and Lineage ~100mb it sending more responses and really fast.

  7. #7
    Diargg is offline Senior Member
    Join Date
    Feb 2012
    Posts
    117
    Rep Power
    0

    Default Re: My ip lags, localhost does not

    What kind of lag are you talking about? On the order of seconds? or ms? And what "space" are you talking about? Surely not bandwidth (Lineage @ 100mb (MB? Mbit? Mbps?) ?)

  8. #8
    Daslee's Avatar
    Daslee is offline Member
    Join Date
    Mar 2012
    Location
    Plunge, Lithuania
    Posts
    36
    Rep Power
    0

    Default Re: My ip lags, localhost does not

    Quote Originally Posted by Diargg View Post
    What kind of lag are you talking about? On the order of seconds? or ms? And what "space" are you talking about? Surely not bandwidth (Lineage @ 100mb (MB? Mbit? Mbps?) ?)
    The lag is that when i move my graphics with arrow keys, server gets new coordinates instantly (request), then it must send to all clients that new coordinates (response), and it sends it after about half second or after second i don't know, didn't counted.. So when i hold my arrow key it looks like moving good, but when i release it, it still moves for about an ~second or two.

    I can send you my server and client source codes to your e-mail if you want, then you can see on your own computer what is the problem and try to find where is that problem.
    Last edited by Daslee; 04-09-2012 at 06:12 PM.

  9. #9
    Diargg is offline Senior Member
    Join Date
    Feb 2012
    Posts
    117
    Rep Power
    0

    Default Re: My ip lags, localhost does not

    And what "space" are you talking about? Surely not bandwidth (Lineage @ 100mb (MB? Mbit? Mbps?) ?)
    Also, is there any delay in when it begins to move? ie you press left, and it waits a second before moving?

  10. #10
    Daslee's Avatar
    Daslee is offline Member
    Join Date
    Mar 2012
    Location
    Plunge, Lithuania
    Posts
    36
    Rep Power
    0

    Default Re: My ip lags, localhost does not

    Quote Originally Posted by Diargg View Post
    Also, is there any delay in when it begins to move? ie you press left, and it waits a second before moving?
    No. Here is my movement code:
    Java Code:
    public void keyPressed(KeyEvent e) {
    		int code = e.getKeyCode();
    		if(code == KeyEvent.VK_UP){
    			y -= moveSpeed;
    			for(int i=0; i<Objects.size(); i++){
    				ItemObject obj = (ItemObject)Objects.get(i);
    				if(Collision(x, y, radius, radius, obj.getX(), obj.getY(), obj.getWidth(), obj.getHeight()))
    					y += (moveSpeed * 1.5);
    			}
    			NakovChatClientGUI.sender.sendMsg("UPDATE:" + x + ":" + y);
    		}else if(code == KeyEvent.VK_DOWN){
    			y += moveSpeed;
    			for(int i=0; i<Objects.size(); i++){
    				ItemObject obj = (ItemObject)Objects.get(i);
    				if(Collision(x, y, radius, radius, obj.getX(), obj.getY(), obj.getWidth(), obj.getHeight()))
    					y -= (moveSpeed * 1.5);
    			}
    			NakovChatClientGUI.sender.sendMsg("UPDATE:" + x + ":" + y);
    		}else if(code == KeyEvent.VK_LEFT){
    			x -= moveSpeed;
    			for(int i=0; i<Objects.size(); i++){
    				ItemObject obj = (ItemObject)Objects.get(i);
    				if(Collision(x, y, radius, radius, obj.getX(), obj.getY(), obj.getWidth(), obj.getHeight()))
    					x += (moveSpeed * 1.5);
    			}
    			NakovChatClientGUI.sender.sendMsg("UPDATE:" + x + ":" + y);
    		}else if(code == KeyEvent.VK_RIGHT){
    			x += moveSpeed;
    			for(int i=0; i<Objects.size(); i++){
    				ItemObject obj = (ItemObject)Objects.get(i);
    				if(Collision(x, y, radius, radius, obj.getX(), obj.getY(), obj.getWidth(), obj.getHeight()))
    					x -= (moveSpeed * 1.5);
    			}
    			NakovChatClientGUI.sender.sendMsg("UPDATE:" + x + ":" + y);
    		}
    	}
    Sorry for my bad English.

  11. #11
    Diargg is offline Senior Member
    Join Date
    Feb 2012
    Posts
    117
    Rep Power
    0

    Default Re: My ip lags, localhost does not

    That's not quite what I meant. I meant to ask if there is any lag when you start to press an arrow key as well.

    Also, answer this:
    And what "space" are you talking about? Surely not bandwidth (Lineage @ 100mb (MB? Mbit? Mbps?) ?)

  12. #12
    Daslee's Avatar
    Daslee is offline Member
    Join Date
    Mar 2012
    Location
    Plunge, Lithuania
    Posts
    36
    Rep Power
    0

    Default Re: My ip lags, localhost does not

    Quote Originally Posted by Diargg View Post
    That's not quite what I meant. I meant to ask if there is any lag when you start to press an arrow key as well.

    Also, answer this:
    No, there is no lag when i start to press arrow key.
    Lineage server i mean files size, it loading so much files and sending info from files to client.
    Sorry for my bad English.

  13. #13
    Diargg is offline Senior Member
    Join Date
    Feb 2012
    Posts
    117
    Rep Power
    0

    Default Re: My ip lags, localhost does not

    There are a few file sizes involved in a client - it's size on your hard drive, in your system memory, and the size of the files it sends over the network. You should specify which that is referring to.

    So, concerning lag - can you think of any reasons why there's lag when you let go of the button, but none when you press it?

  14. #14
    Daslee's Avatar
    Daslee is offline Member
    Join Date
    Mar 2012
    Location
    Plunge, Lithuania
    Posts
    36
    Rep Power
    0

    Default Re: My ip lags, localhost does not

    Quote Originally Posted by Diargg View Post
    There are a few file sizes involved in a client - it's size on your hard drive, in your system memory, and the size of the files it sends over the network. You should specify which that is referring to.

    So, concerning lag - can you think of any reasons why there's lag when you let go of the button, but none when you press it?
    Yes i'm thinking about one reason, but didn't tried to fix it. When i move it sends one request to server (instantly), and when i need to get response (that thing which comes after ~second) im getting two respones, first one is CLEAR another: RESPAWN:X:Y
    CLEAR - Clears all drawed squares (players) on my window from ArrayList<Point>
    RESPAWN - Add square (player) to my window, to ArrayList<Point> and reapints
    And i got RESPAWN that times how much players are online.

    Example: There are 3 players, when that 2 others (not me) moves in both time (not necessarily in both time) they send message to server:
    1 player: UPDATE:10:10
    2 player: UPDATE:20:20

    And then i'll got from server 3 messages:
    CLEAR
    RESPAWN:10:10
    RESPAWN:20:20

    Maybe that few messages (responses) getting makes lag?
    Last edited by Daslee; 04-09-2012 at 11:31 PM.
    Sorry for my bad English.

  15. #15
    Diargg is offline Senior Member
    Join Date
    Feb 2012
    Posts
    117
    Rep Power
    0

    Default Re: My ip lags, localhost does not

    And where do you redraw? Can you post a simplified version of what your client and server do upon receiving a command? Simplified, not code. A flowchart would be great.

  16. #16
    Daslee's Avatar
    Daslee is offline Member
    Join Date
    Mar 2012
    Location
    Plunge, Lithuania
    Posts
    36
    Rep Power
    0

    Default Re: My ip lags, localhost does not

    When i click any arrow key to move it sends message to server:
    Java Code:
    UPDATE:x:y
    with my current coordinates. Then server got that message and update in his ArrayList<Point> that location. Then tells to all clients to clear all drawed players (Sends message: CLEAR) And after send CLEAR message it sends all players points (not i one message, every player point separate message) with this:
    Java Code:
    RESPAWN:x:y
    and then when clients got that RESPAWN message they add to their own ArrayList<Point> new points of every player and instantly repaints with: JPane.repaint();
    I do not know how to exatcly tell flowchart, but i really can give you my source code of server and client if you do not understanding what im saying.
    Sorry for my bad English.

  17. #17
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

    Default Re: My ip lags, localhost does not

    A few points - if I understand up to this point. I'd recommend 'bunching' the messages between client and server (as opposed to multiple communications as described in the last post). I don't know how you establish communication between client and server, but if it requires a new Socket creation each time you should consider caching the connections. Lastly, you do not discuss the configuration of your server, but if it is single threaded you may wish to look into multi-threading its analysis/communications.

  18. #18
    Daslee's Avatar
    Daslee is offline Member
    Join Date
    Mar 2012
    Location
    Plunge, Lithuania
    Posts
    36
    Rep Power
    0

    Default Re: My ip lags, localhost does not

    Im using Nakov's multi-threaded socket server.
    Chat Client/Server Example

    And it does not create new socket for each client.
    Sorry for my bad English.

  19. #19
    Daslee's Avatar
    Daslee is offline Member
    Join Date
    Mar 2012
    Location
    Plunge, Lithuania
    Posts
    36
    Rep Power
    0

    Default Re: My ip lags, localhost does not

    Quote Originally Posted by doWhile View Post
    A few points - if I understand up to this point. I'd recommend 'bunching' the messages between client and server (as opposed to multiple communications as described in the last post). I don't know how you establish communication between client and server, but if it requires a new Socket creation each time you should consider caching the connections. Lastly, you do not discuss the configuration of your server, but if it is single threaded you may wish to look into multi-threading its analysis/communications.
    Can you tell me how to do "bunching" ?
    Sorry for my bad English.

  20. #20
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,058
    Rep Power
    6

    Default Re: My ip lags, localhost does not

    (Didn't read all 18 preceding comments... sorry if this has been said.)

    My experience with cheap home routers is that they often lag badly if you connect to a forwarded (NAT) port on their public interface. Example: my router's public IP is 68.226.(something), my laptop's private IP is 192.168.1.(something), and the loopback is of course 127.0.0.1. If I'm running a game server and connect to the loopback or to the 192... address, it works fine. But if I connect to my public IP, the router behaves very badly.
    Get in the habit of using standard Java naming conventions!

Page 1 of 2 12 LastLast

Similar Threads

  1. configuring localhost, working with IBM RAD
    By clipod in forum Eclipse
    Replies: 6
    Last Post: 12-03-2010, 04:23 PM
  2. jboss server, localhost as ip...
    By Sno in forum Eclipse
    Replies: 1
    Last Post: 06-23-2010, 08:30 PM
  3. My encrypting thingy lags alot..
    By Addez in forum New To Java
    Replies: 3
    Last Post: 09-15-2009, 11:33 PM
  4. java-vnc connection to localhost
    By pdc124 in forum Java Applets
    Replies: 0
    Last Post: 07-26-2009, 01:23 PM
  5. connecting to a wsdl on localhost
    By david99world in forum Eclipse
    Replies: 0
    Last Post: 01-23-2009, 10:25 PM

Posting Permissions

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