Quackster
a devbest user says what
Gamma
The section get's shitty after a while from seeing so much customs, cms and C# releases. So I decided to add in a little bit of spice by creating a multi-threaded JAVA server. It doesn't use Netty at all or any other addons.
How does it work?
Well it's simple. Every time there is a new connection, a new thread is created to handle it. This allows multi-tasking when handling clients.
How do I change the port?
Go to environment.java and you'll see where to change it.
Can we see some code?
A picture
The section get's shitty after a while from seeing so much customs, cms and C# releases. So I decided to add in a little bit of spice by creating a multi-threaded JAVA server. It doesn't use Netty at all or any other addons.
Please read this important note:
Gamma is unfinished, do not use it for a hotel. It is only for educational purposes. Please do not ask for help in this thread or how to open it.
Features
Features
- Hardcoded packet handling (thaaa best feature evarrr)
- Thread manager.
- Allows one ip per connection
- Multi-threaded
How does it work?
Well it's simple. Every time there is a new connection, a new thread is created to handle it. This allows multi-tasking when handling clients.
How do I change the port?
Go to environment.java and you'll see where to change it.
Can we see some code?
Code:
package gamma.threading;
import gamma.main.Environment;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;
public class GammaThreadManager
{
private Map<String, GammaThread> Clients;
private Map<GammaThread, Thread> Threads;
public GammaThreadManager()
{
this.Clients = new HashMap<String, GammaThread>();
this.Threads = new HashMap<GammaThread, Thread>();
}
public void AcceptClient(Socket Client)
{
/*
* Get existing thread if possible
*/
GammaThread _existingThread = Clients.get(this.getIp(Client));
/*
* Check for existing ip address and dispose them
*/
if (_existingThread != null)
{
/*
* Stop thread.
*/
Clients.get(this.getIp(Client)).Disposed = true;
Threads.get(_existingThread).interrupt();
/*
* Remove both
*/
Clients.remove(this.getIp(Client));
Threads.remove(_existingThread);
}
/*
* Add client to map.
*/
GammaThread _gThread = new GammaThread(Client);
this.Clients.put(this.getIp(Client), _gThread);
/*
* Add new thread to map.
*/
this.Threads.put(_gThread, new Thread(_gThread));
/*
* Start thread.
*/
this.Threads.get(_gThread).start();
}
public String getIp(Socket Socket)
{
return Socket.getLocalAddress().toString().replace("/", "");
}
}
A picture
You must be registered for see links