- Joined
- May 17, 2007
- Messages
- 2,468
- Reaction score
- 681
Hey,
For about... 2 - 3 Weeks now, I've been taking a part-time java cource at a community college, and I'm more experienced at java sockets, ( basically java overall ). So i've decided to test out what i could do and see if i can make a better socket connection from scratch and see if i can make it better than the default one. So far, it's alright.. the only problem is it uses some-what more CPU ( stays in the 15 - 20% range mark 24/7 ), But seriously, it's overall better than the current one that is used in 503's and 508's.
Those are what basically buffers via client to client.
So basically, my whole point is im trying to waste less connection speed, and less RAM.
Introducing less convected coding helps rather than making it read via package.
Reading/Writing to your client ( btw, these are just codes i'm currently devoloping on, there not confirmed yet )
Using a accept() instead of request function saves time on login.
All tcp clients listen correctly
Listening to the GSC keys and update keys via client class
Allows clients registering via a stamp table.
I Probably won't be releasing this to public, instead i will release to friends.
Mostly because when i release things people don't learn from it.. they just use it without knowledge.
For about... 2 - 3 Weeks now, I've been taking a part-time java cource at a community college, and I'm more experienced at java sockets, ( basically java overall ). So i've decided to test out what i could do and see if i can make a better socket connection from scratch and see if i can make it better than the default one. So far, it's alright.. the only problem is it uses some-what more CPU ( stays in the 15 - 20% range mark 24/7 ), But seriously, it's overall better than the current one that is used in 503's and 508's.
PHP:
IntBuffer buffer = IntBuffer.allocate(10);
for (int i=0; i < buffer.capacity(); i++) {
buffer.put(i);
}
PHP:
buffer.position(0);
while (buffer.hasRemaining()) {
int i = buffer.get();
System.out.println("i="+i);
}
Those are what basically buffers via client to client.
So basically, my whole point is im trying to waste less connection speed, and less RAM.
Introducing less convected coding helps rather than making it read via package.
![TheAJ - [Tut] Converting To A Custom Socket - RaGEZONE Forums TheAJ - [Tut] Converting To A Custom Socket - RaGEZONE Forums](http://www.onjava.com/onjava/2002/09/04/graphics/Fig1.gif)
PHP:
create SocketChannel;
create Selector
associate the SocketChannel to the Selector
for(;;) {
waiting events from the Selector;
event arrived; create keys;
for each key created by Selector {
check the type of request;
isAcceptable:
get the client SocketChannel;
associate that SocketChannel to the Selector;
record it for read/write operations
continue;
isReadable:
get the client SocketChannel;
read from the socket;
continue;
isWriteable:
get the client SocketChannel;
write on the socket;
continue;
}
}
Reading/Writing to your client ( btw, these are just codes i'm currently devoloping on, there not confirmed yet )
PHP:
InputStream in = conn.getInputStream();
InputStreamReader rdr = new InputStreamReader(in);
LineNumberReader lnr = new LineNumberReader(rdr);
Request req = new Request();
while (!req.isComplete() )
{
String s = lnr.readLine();
req.addLine(s);
}
Using a accept() instead of request function saves time on login.
PHP:
ServerSocketChannel serverChannel = ServerSocketChannel.open();
serverChannel.configureBlocking(false);
InetAddress ia = InetAddress.getLocalHost();
InetSocketAddress isa = new InetSocketAddress(ia, port );
serverChannel.socket().bind(isa);
All tcp clients listen correctly
PHP:
SocketChannel socket;
if (key.isAcceptable()) {
System.out.println("Acceptable Key");
ServerSocketChannel ssc = (ServerSocketChannel) key.channel();
socket = (SocketChannel) ssc.accept();
socket.configureBlocking(false);
SelectionKey another =
socket.register(sel,SelectionKey.OP_READ|SelectionKey.OP_WRITE);
}
if (key.isReadable()) {
System.out.println("Readable Key");
String ret = readMessage(key);
if (ret.length() > 0) {
writeMessage(socket,ret);
}
}
if (key.isWritable()) {
System.out.println("Writable Key");
String ret = readMessage(key);
socket = (SocketChannel)key.channel();
if (result.length() > 0 ) {
writeMessage(socket,ret);
}
}
Listening to the GSC keys and update keys via client class
PHP:
SelectionKey acceptKey = serverChannel.register(sel, SelectionKey.OP_ACCEPT);
while (acceptKey.selector().select() > 0 ){
Allows clients registering via a stamp table.
I Probably won't be releasing this to public, instead i will release to friends.
Mostly because when i release things people don't learn from it.. they just use it without knowledge.