Jump to content
  • Advertisement
Sign in to follow this  
xslaught

AS3 Client/Java Server - Extra socket connection when using browser

This topic is 2435 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I am using a AS3 client and Java server.

In debug mode when I use the AS3 client to connect to the java game server. Only 1 client makes the connection to the game server.
When i test the AS3 application on the browser and connect to the java game server, for some odd reason 2 different connections are made instead of 1. This is not the policy server but the game server. I already verify that the client retrieves the policy file from the policy server.

I have no explaination for why this happens. When I try to read the socket made from the extra connection, the number of bytes available to be read is 0. So far I've used a method to just kick the unwanted connection which doesn't really help explain to me why this happens.

I am testing everything on a local machine. I am using a packet signature for testing purposes. Every packet sent from the client has a packet signature at the beginning of the packet that should match with the one I set in the server's config file.

The is the output from the debug console:
Note here the:
World Server: Client connection from /127.0.0.1:51117 TIME: 1324423345045
World Server: Client connection from /127.0.0.1:51118 TIME: 1324423345054


Policy server started
Account Server started
World Server started
Policy Server: Client connection from /127.0.0.1:51114
Policy Server: Client says '<policy-file-request/>'
Policy Server: Policy sent to client
Policy Server: Connection to /127.0.0.1:51114 closed
Account Server: Client connection from /127.0.0.1:51115
Account Server: Recieved packet with cmd: 1 dataType: 8 messageLength: 10 from /127.0.0.1:51115
Account Server: Sending packet with cmd: 4 dataType: 1 messageLength: 49 msg [B@151a64ed to /127.0.0.1:51115
Account Server: Sent packet: [B@77d80e6d to /127.0.0.1:51115
Account Server: Connection to /127.0.0.1:51115 closed
Account Server: Client /127.0.0.1:51115 was removed
World Server: Client connection from /127.0.0.1:51117 TIME: 1324423345045
World Server: Client connection from /127.0.0.1:51118 TIME: 1324423345054
World Server: Recieved packet with cmd: 4 dataType: 9 messageLength: 12 from /127.0.0.1:51118 TIME: 1324423345058
World Server: Invalid packet from /127.0.0.1:51117 with numBytes 0 TIME: 1324423345058
World Server: Invalid packet from /127.0.0.1:51117 with numBytes 0 TIME: 1324423345059
World Server: Invalid packet from /127.0.0.1:51117 with numBytes 0 TIME: 1324423345059
World Server: Invalid packet from /127.0.0.1:51117 with numBytes 0 TIME: 1324423345061
World Server: Invalid packet from /127.0.0.1:51117 with numBytes 0 TIME: 1324423345062
World Server: Invalid packet from /127.0.0.1:51117 with numBytes 0 TIME: 1324423345062
World Server: Invalid packet from /127.0.0.1:51117 with numBytes 0 TIME: 1324423345062
World Server: Invalid packet from /127.0.0.1:51117 with numBytes 0 TIME: 1324423345062
World Server: Invalid packet from /127.0.0.1:51117 with numBytes 0 TIME: 1324423345062
World Server: Invalid packet from /127.0.0.1:51117 with numBytes 0 TIME: 1324423345066
World Server: Invalid packet from /127.0.0.1:51117 with numBytes 0 TIME: 1324423345067
World Server: Connection to /127.0.0.1:51117 closed TIME: 1324423345068
World Server: Client /127.0.0.1:51117 was removed TIME: 1324423345068
World Server: Sending packet with cmd: 18 dataType: 1 messageLength: 8 msg [B@4ca31e1b to /127.0.0.1:51118 TIME: 1324423345069
World Server: Sent packet: [B@7f081d2e to /127.0.0.1:51118 TIME: 1324423345071
World Server: Broadcast message [B@4ca31e1b was sent to 1 clients TIME: 1324423345071
World Server: Player id 1 not found to be online but online in database TIME: 1324423345216
World Server: Set player id 1 to offline TIME: 1324423345216
World Server: Sending packet with cmd: 5 dataType: 8 messageLength: 9 msg Not found to /127.0.0.1:51118 TIME: 1324423345217
World Server: Sent packet: [B@4ee91f5d to /127.0.0.1:51118 TIME: 1324423345221
World Server: Connection to /127.0.0.1:51118 closed TIME: 1324423345221
World Server: Client /127.0.0.1:51118 was removed TIME: 1324423345223
World Server: Broadcast message [B@2b0a3b24 was sent to 0 clients TIME: 1324423345223
Account Server: Client connection from /127.0.0.1:51120
Account Server: Client connection from /127.0.0.1:51121
Account Server: Recieved packet with cmd: 0 dataType: 0 messageLength: 0 from /127.0.0.1:51120
Account Server: Recieved packet with cmd: 1 dataType: 8 messageLength: 10 from /127.0.0.1:51121
Account Server: Invalid packet from /127.0.0.1:51120
Account Server: Connection to /127.0.0.1:51120 closed
Account Server: Client /127.0.0.1:51120 was removed
Account Server: Sending packet with cmd: 3 dataType: 1 messageLength: 49 msg [B@7b112783 to /127.0.0.1:51121
Account Server: Sent packet: [B@23394894 to /127.0.0.1:51121
Account Server: Connection to /127.0.0.1:51121 closed
Account Server: Client /127.0.0.1:51121 was removed
World Server: Client connection from /127.0.0.1:51123 TIME: 1324423347348
World Server: Invalid packet from /127.0.0.1:51123 with numBytes 0 TIME: 1324423347350
World Server: Invalid packet from /127.0.0.1:51123 with numBytes 0 TIME: 1324423347351
World Server: Invalid packet from /127.0.0.1:51123 with numBytes 0 TIME: 1324423347351
World Server: Invalid packet from /127.0.0.1:51123 with numBytes 0 TIME: 1324423347351
World Server: Invalid packet from /127.0.0.1:51123 with numBytes 0 TIME: 1324423347351
World Server: Invalid packet from /127.0.0.1:51123 with numBytes 0 TIME: 1324423347351
World Server: Client connection from /127.0.0.1:51124 TIME: 1324423347352
World Server: Connection to /127.0.0.1:51123 closed TIME: 1324423347354
World Server: Client /127.0.0.1:51123 was removed TIME: 1324423347354
World Server: Exception (writeToAll): null TIME: 1324423347355
World Server: Invalid packet from /127.0.0.1:51123 with numBytes 0 TIME: 1324423347352
World Server: Invalid packet from /127.0.0.1:51123 with numBytes 0 TIME: 1324423347353
World Server: Invalid packet from /127.0.0.1:51123 with numBytes 0 TIME: 1324423347353
World Server: Invalid packet from /127.0.0.1:51123 with numBytes 0 TIME: 1324423347353
World Server: Invalid packet from /127.0.0.1:51123 with numBytes 0 TIME: 1324423347354
World Server: Recieved packet with cmd: 10 dataType: 9 messageLength: 12 from /127.0.0.1:51124 TIME: 1324423347359
World Server: Sending packet with cmd: 11 dataType: 1 messageLength: 14 msg [B@27bc82e7 to /127.0.0.1:51124 TIME: 1324423347527
World Server: Sent packet: [B@49362012 to /127.0.0.1:51124 TIME: 1324423347528
World Server: Broadcast message [B@27bc82e7 was sent to 1 clients TIME: 1324423347528
World Server: Recieved packet with cmd: 12 dataType: 9 messageLength: 12 from /127.0.0.1:51124 TIME: 1324423347581
World Server: Sending packet with cmd: 12 dataType: 1 messageLength: 14 msg [B@509ced8e to /127.0.0.1:51124 TIME: 1324423347581
World Server: Sent packet: [B@6eb02efa to /127.0.0.1:51124 TIME: 1324423347582



This is the code have for the packet action thread for the world server:


public void run() {
while(this.socket.isConnected() && !this.socket.isClosed())
{
try {
this.packet = new Packet(this.socket);
this.packet.read();
} catch(Exception e) {
DebugConsole.print("Exception (Packet.read): Socket " + this.socket.getRemoteSocketAddress() + "|e: "+e+"|"+ e.getMessage());
finalize();
break;
}


The code for the packet:


public void read() throws Exception {
// Get header data from packet
int numBytes = this.socket.getInputStream().available();
header = new byte[9];
this.socket.getInputStream().read(header, 0, 9);
ByteBuffer buffer = ByteBuffer.allocate(2);
buffer.put(header[0]);
buffer.put(header[1]);
packetSig = buffer.getShort(0);
if(packetSig != Config.packetSig) {
this.command = 0;
DebugConsole.print("Invalid packet from "+this.socket.getRemoteSocketAddress()+ " with numBytes "+numBytes, true);
return;
}

buffer = ByteBuffer.allocate(2);
buffer.put(header[2]);
buffer.put(header[3]);
command = buffer.getShort(0);
dataType = header[4];

buffer = ByteBuffer.allocate(4);
buffer.put(header[5]);
buffer.put(header[6]);
buffer.put(header[7]);
buffer.put(header[8]);
messageLength = buffer.getInt(0);
DebugConsole.print("Recieved packet with cmd: "+command+" dataType: "+dataType+" messageLength: "+messageLength+" from "+this.socket.getRemoteSocketAddress());

// Get body data from packet
message = new byte[messageLength];
this.socket.getInputStream().read(message);
}


The code for the world server:



public void run() {
setName("World Server");
try {
this.serverSocket = new ServerSocket(this.port);
this.listening = true;
while (listening) {
Socket socket = this.serverSocket.accept();
socket.setTcpNoDelay(true);
DebugConsole.print("Client connection from " + socket.getRemoteSocketAddress());
PacketAction socketConnection = new PacketAction(socket, this);
socketConnection.start();
this.clientConnections.add(socketConnection);
};
}
catch (Exception e) {
DebugConsole.print("Exception (run): " + e.getMessage());
}
}


This is the debug console output when I run in debug mode (non-browser):


Policy server started
Account Server started
World Server started
Account Server: Client connection from /127.0.0.1:52340
Account Server: Recieved packet with cmd: 1 dataType: 8 messageLength: 10 from /127.0.0.1:52340
Account Server: Sending packet with cmd: 4 dataType: 1 messageLength: 49 msg [B@6115273a to /127.0.0.1:52340
Account Server: Sent packet: [B@33c282a1 to /127.0.0.1:52340
Account Server: Connection to /127.0.0.1:52340 closed
Account Server: Client /127.0.0.1:52340 was removed
World Server: Client connection from /127.0.0.1:52344 TIME: 1324429062336
World Server: Recieved packet with cmd: 4 dataType: 9 messageLength: 12 from /127.0.0.1:52344 TIME: 1324429062346
World Server: Player id 1 not found to be online but online in database TIME: 1324429062542
World Server: Set player id 1 to offline TIME: 1324429062542
World Server: Sending packet with cmd: 5 dataType: 8 messageLength: 9 msg Not found to /127.0.0.1:52344 TIME: 1324429062543
World Server: Sent packet: [B@3a21b220 to /127.0.0.1:52344 TIME: 1324429062547
World Server: Connection to /127.0.0.1:52344 closed TIME: 1324429062548
World Server: Client /127.0.0.1:52344 was removed TIME: 1324429062548
World Server: Broadcast message [B@7a3570b0 was sent to 0 clients TIME: 1324429062548
Account Server: Client connection from /127.0.0.1:52346
Account Server: Recieved packet with cmd: 1 dataType: 8 messageLength: 10 from /127.0.0.1:52346
Account Server: Sending packet with cmd: 3 dataType: 1 messageLength: 49 msg [B@4ca31e1b to /127.0.0.1:52346
Account Server: Sent packet: [B@690da5eb to /127.0.0.1:52346
Account Server: Connection to /127.0.0.1:52346 closed
Account Server: Client /127.0.0.1:52346 was removed
World Server: Client connection from /127.0.0.1:52348 TIME: 1324429064068
World Server: Recieved packet with cmd: 10 dataType: 9 messageLength: 12 from /127.0.0.1:52348 TIME: 1324429064070
World Server: Sending packet with cmd: 11 dataType: 1 messageLength: 14 msg [B@42a9c09e to /127.0.0.1:52348 TIME: 1324429064237
World Server: Sent packet: [B@16a4e743 to /127.0.0.1:52348 TIME: 1324429064244
World Server: Broadcast message [B@42a9c09e was sent to 1 clients TIME: 1324429064244
World Server: Recieved packet with cmd: 12 dataType: 9 messageLength: 12 from /127.0.0.1:52348 TIME: 1324429064284
World Server: Sending packet with cmd: 12 dataType: 1 messageLength: 14 msg [B@7f2a3793 to /127.0.0.1:52348 TIME: 1324429064284
World Server: Sent packet: [B@2ca6d51e to /127.0.0.1:52348 TIME: 1324429064285

Share this post


Link to post
Share on other sites
Advertisement
If there are two connections, then that's much more likely to be a client thing than a server thing. Except you didn't show any client code!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!