Hello i am new here, i want to ask about a problem of mine.
I have made a server code, so i can send commands from other program C#
i made that but my problem is when i start the java program because is Loading.
The Server is starting at the middle of it, so when i start it is stacking at BufferedRead.Readline so is not continiu at the other loading.
Can someone help me with it?
here the code:
package extensions.ServerManager.Server;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.lang.ClassNotFoundException;
import java.lang.Runnable;
import java.lang.Thread;
import java.net.ServerSocket;
import java.net.Socket;
import com.l2jserver.gameserver.cache.HtmCache;
import com.l2jserver.gameserver.datatables.MultiSell;
import com.l2jserver.gameserver.datatables.NpcTable;
import com.l2jserver.gameserver.instancemanager.QuestManager;
import core.L2VoyagerLoader;
import extensions.ServerManager.ServerManagerConfig;
public class ServerManagerSocket
{
private ServerSocket server;
public ServerManagerSocket() {
try {
server = new ServerSocket(ServerManagerConfig.SM_PORT);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void loadSocket()
{
ServerManagerSocket sms = new ServerManagerSocket();
sms.handleConnection();
}
public void handleConnection() {
System.out.println("Waiting for manager command...");
//
// The server do a loop here to accept all connection initiated by the
// client application.
//
while (true) {
try {
Socket socket = server.accept();
new ConnectionHandler(socket);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
class ConnectionHandler implements Runnable {
private Socket socket;
public ConnectionHandler(Socket socket) {
this.socket = socket;
Thread t = new Thread(this);
t.start();
}
public void run() {
try
{
//
// Read a message sent by client application
//
BufferedReader br=new BufferedReader(new
InputStreamReader(socket.getInputStream()));
System.out.println(br.readLine());
PrintWriter wr=new PrintWriter(new
OutputStreamWriter(socket.getOutputStream()),true);
String message = br.readLine();
int comid = Integer.getInteger(message);
switch(comid)
{
//Reload Voyager Engine
case 259023:
L2VoyagerLoader.load();
wr.println("Voyager Scripts have been reloaded");
break;
//Reload HTML
case 293474:
HtmCache.getInstance().reload();
wr.println("Cache[HTML]: "+ HtmCache.getInstance().getMemoryUsage() + " megabytes on " + HtmCache.getInstance().getLoadedFiles() + " files loaded");
break;
//Reload Multisell
case 234256:
MultiSell.getInstance().reload();
wr.println("All Multisells have been reloaded");
break;
//Reload NPC
case 534452:
NpcTable.getInstance().reloadAllNpc();
wr.println("All NPCs have been reloaded");
break;
//Reload Quests
case 354574:
QuestManager.getInstance().reloadAllQuests();
wr.println("All Quests have been reloaded");
break;
}
wr.close();
br.close();
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}