Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (552)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Socket quirks  (Read 1689 times)
0 Members and 1 Guest are viewing this topic.
Online Riven
« League of Dukes »

JGO Overlord


Medals: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Posted 2010-07-12 14:37:09 »

I have a networking problem that is more or less haunting me.

I have reduced the problem down to only a... port number!


Let me begin with the setup:
  • I have a server, with 1gbit ethernet (Linux 2.6.18)
  • I have a home connection with 1mbit upload (~100KB/sec upload)
  • I send 4MB (random bytes) from the client to the server, and the server simply accepts,reads,discards the data.

When the ServerSocket is listing on port 2048, everything is well.
The (manually) interleaved STDOUT from the server and client looks (a bit) like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
CLIENT: 95KB/sec
                                               SERVER: 93KB/sec
CLIENT: 92KB/sec
                                               SERVER: 94KB/sec
CLIENT: 94KB/sec
                                               SERVER: 97KB/sec
CLIENT: 96KB/sec
                                               SERVER: 92KB/sec
CLIENT: 93KB/sec
                                               SERVER: 92KB/sec
...


When the ServerSocket is listing on port 80, everything is b0rked.
The (manually) interleaved STDOUT from the server and client looks (a bit) like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
CLIENT: 500KB/sec (impossible)
                                               SERVER: 37KB/sec
CLIENT: 37KB/sec
                                               SERVER: 4KB/sec
CLIENT: 19KB/sec
                                               SERVER: 8KB/sec
CLIENT: 0KB/sec
                                               SERVER: 3KB/sec
CLIENT: 72KB/sec
                                               SERVER: 103KB/sec
...



It is literally the same code, but when I change the port, everything goes belly up. The client thinks it sent 500KB in the first second, which is impossible, and after that, the connection is flaky at best, most of the time I/O over port 80 is 4-5x slower than port 2048, often gaps in traffic for 3 seconds, sometimes even dropping the connection.


I looked at the (iptables) firewall, and all is properly setup:
1  
2  
3  
4  
5  
6  
7  
8  
.........
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:80
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:110
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:443
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:2048
REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-port-unreachable



Naturally I cannot host the service on port 2048, as it is a publicly available HTTP server.
Note that the test-application is NOT a HTTP server, and so simple it can be considered 'bug-free' ...
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
            try
            {
               ServerSocket ss = new ServerSocket(80 <---> 2048, 50, InetAddress.getByName("123.456.789.012"));
               while (true)
               {
                  final Socket s = ss.accept();

                  new Thread(new Runnable()
                  {
                     @Override
                     public void run()
                     {
                        try
                        {
                           InputStream in = new BufferedInputStream(s.getInputStream());
                           OutputStream out = s.getOutputStream();

                           byte[] buf = new byte[8 * 1024];

                           long last = System.currentTimeMillis();
                           int accum = 0;

                           while (true)
                           {
                              long now = System.currentTimeMillis();
                              int got = in.read(buf);
                              if (got == -1)
                                 throw new EOFException();
                              accum += got;

                              if (now - last > 1000L)
                              {
                                 System.out.println("accum=" + (accum / 1024) + "K");
                                 last += 1000L;
                                 accum = 0;
                              }
                           }
                        }
                        catch (IOException exc)
                        {
                           exc.printStackTrace();
                        }
                     }
                  }).start();
               }
            }
            catch (IOException exc)
            {
               exc.printStackTrace();
            }


Socket.sendBufferSize /  Socket.recvBufferSize are 8K.

I'm out of ideas... persecutioncomplex I can't get the TCP connection on port 80 stable and reliable to save my life! You can imagine this is critical to any webapp...

Does somebody have an idea what can cause this?

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline princec

JGO Kernel


Medals: 363
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #1 - Posted 2010-07-12 14:42:47 »

Your ISP, your server, or perhaps even your router, is intercepting port 80 sockets and attempting to "optimise" HTTP requests. Which of course, you're not doing. Best find out which of the 3 it is.

Cas Smiley

Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #2 - Posted 2010-07-12 14:44:32 »

I've never been able to get anything working over port 80, for whatever reason. A couple times I figured I would try to use it so that I wouldn't need to worry about firewalls, but no dice. I think you might need to treat it differently in order to get the OS to allow you to use it, or something. Otherwise I don't know exactly why.

As a note, I never tried with a totally "bug free" server (I've only given it a go from my personal machines), but yeah port 80 has never been happy for me.

See my work:
OTC Software
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online Riven
« League of Dukes »

JGO Overlord


Medals: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #3 - Posted 2010-07-12 14:49:55 »

Your ISP, your server, or perhaps even your router, is intercepting port 80 sockets and attempting to "optimise" HTTP requests. Which of course, you're not doing. Best find out which of the 3 it is.

Cas Smiley

Good suggestion. It's probably that... but the thing is, the original application that had severe problems, was actually using the HTTP protocol, and I run this also on another server, provided by the same ISP, in the same rack (or near it), and it works flawlessly. I also run it on 2 more servers hosted in other datacenters by other ISPs... I bet the only thing I can do is creating a support ticket... Angry This is ridiculous, I lost so much time over this, narrowing it down.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline delt0r

JGO Knight


Medals: 27
Exp: 18 years


Computers can do that?


« Reply #4 - Posted 2010-07-12 21:41:40 »

My isp hacks the hell out of port 80. So i am betting  princec  is correct. I get an initial burst on port 80 well above my average quoted bandwidth, which then stalls before settling down at the quoted rate some many seconds later.  I know this is not the router in my case as i have tested a few, and i set  them up myself.

This is pretty common, because for most people this make the "web" much more responsive. Most pages fit in the initial burst.

I have no special talents. I am only passionately curious.--Albert Einstein
Online Riven
« League of Dukes »

JGO Overlord


Medals: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #5 - Posted 2010-07-12 22:54:03 »

That initial (fake) burst wouldn't be that bad, but after that, the connection is unreliable at best. As said, it hardly manages to transfer a few MB, it will get stuck at 0KB/sec for minutes, sometimes, then resuming at a few KB/sec. It's hacked beyond being usable. It never 'settles'.

I'm also not really sure how it makes the websites faster. Maybe for downloading, but remember I'm uploading using POST. The website can only respond when it received the full message. The client only *thinks* it sent 500KB in a split second, but the server has only a few bytes. So the server won't be able to respond any faster (and in my case, it will sometimes even timeout after a few  minutes).

I have this feeling that it's something bad my datacenter-ISP configured, as it works fine in other datacenters, with other datacenter-ISPs (home and office ISP have exactly the same problem with that server on that port).

Currently I run a single application on both ports (created 2 serversockets) and I send the POST requests to port 2048, and the GET requests to port 80. Works flawlessly, but it's a dirty hack.

Anyway, I sent the support ticket, and it will be handled 'soon'. Let's see what they come up with.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Online Riven
« League of Dukes »

JGO Overlord


Medals: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #6 - Posted 2010-07-15 16:12:48 »

Hm... the ISP at the datacenter has no clue, and they say they don't do HTTP throttling or traffic shaping.

So I thought it must be the home/office ISPs (despite that they are different companies), so I did some further testing on a bunch of computers.

Home [PC1 Vista]: problems on port 80
Office [PC2 WinXP]: problems on port 80
Office [PC3 WinXP]: works perfectly! Shocked
Office [PC4 Win7]: problems on port 80


So PC2 and PC3 are almost idential, both running WinXP, attached to the same switch, and one is stable on port 80, and the other is not (both are stable on port 2048).

It seems like some obscure setting in the PCs is causing this...

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #7 - Posted 2010-07-15 17:03:42 »

Wow, that sucks... I'd be very interested to find out the reasons if you ever get this working.

See my work:
OTC Software
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CopyableCougar4 (23 views)
2014-08-22 19:31:30

atombrot (34 views)
2014-08-19 09:29:53

Tekkerue (30 views)
2014-08-16 06:45:27

Tekkerue (28 views)
2014-08-16 06:22:17

Tekkerue (18 views)
2014-08-16 06:20:21

Tekkerue (27 views)
2014-08-16 06:12:11

Rayexar (65 views)
2014-08-11 02:49:23

BurntPizza (41 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (41 views)
2014-08-06 19:49:38
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!