updated datagram sockets, had managed to fuck up the port

This commit is contained in:
jenz 2022-11-19 21:57:25 +01:00
parent eb7ed76d2e
commit 10eedf6529
3 changed files with 58 additions and 55 deletions

View File

@ -93,7 +93,7 @@ public class DataMapper {
ResultSet resultSet = l_pStatement.executeQuery(); ResultSet resultSet = l_pStatement.executeQuery();
if (resultSet.next()) { if (resultSet.next()) {
int count = resultSet.getInt(1); int count = resultSet.getInt(1);
if (count > 35000) { if (count > 13000) {
//System.out.println("cleaning strings: " + l_sSQL); //System.out.println("cleaning strings: " + l_sSQL);
l_pStatement = l_cCon.prepareStatement(l_sSQL); l_pStatement = l_cCon.prepareStatement(l_sSQL);
l_pStatement.executeUpdate(); l_pStatement.executeUpdate();

View File

@ -8,30 +8,28 @@ import java.io.UnsupportedEncodingException;
import java.net.*; import java.net.*;
public class ThreadClient { public class ThreadClient {
public ThreadClient(int port, Datahandler datahandler, StanfordCoreNLP stanfordCoreNLP, StanfordCoreNLP stanfordCoreNLPSentiment) { public ThreadClient(int port, Datahandler datahandler, StanfordCoreNLP stanfordCoreNLP, StanfordCoreNLP stanfordCoreNLPSentiment) {
String hostIP = new settings().getHostIP(); String hostIP = new settings().getHostIP();
if (port == new settings().getHostport() || port == new settings().getHostport2()) { if (port == new settings().getHostport() || port == new settings().getHostport2()) {
hostIP = new settings().getHostIP2(); hostIP = new settings().getHostIP2();
}
try { try {
InetAddress ipAddress = InetAddress.getByName(hostIP);//used ip' InetAddress ipAddress = InetAddress.getByName(hostIP);//used ip's
try (DatagramSocket serverSocket = new DatagramSocket()) { try (DatagramSocket serverSocket = new DatagramSocket(port)) {
while (true) { while (true) {
receiveAndSendPacket(serverSocket, ipAddress, port, datahandler, stanfordCoreNLP, stanfordCoreNLPSentiment); receiveAndSendPacket(serverSocket, ipAddress, port, datahandler, stanfordCoreNLP, stanfordCoreNLPSentiment);
}
} catch (SocketException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} }
} catch (UnknownHostException e) { } catch (SocketException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} catch (UnknownHostException e) {
e.printStackTrace();
} }
} }
private static void receiveAndSendPacket(DatagramSocket serverSocket, InetAddress ipAddress, int port, private static void receiveAndSendPacket(DatagramSocket serverSocket, InetAddress ipAddress, int port,
Datahandler datahandler, StanfordCoreNLP stanfordCoreNLP, StanfordCoreNLP stanfordCoreNLPSentiment) throws Datahandler datahandler, StanfordCoreNLP stanfordCoreNLP, StanfordCoreNLP stanfordCoreNLPSentiment) throws
IOException { IOException {
@ -42,39 +40,37 @@ public class ThreadClient {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
new Thread(() -> { String sentence = new String(receivePacket.getData(), 0,
String sentence = new String(receivePacket.getData(), 0, receivePacket.getLength());
receivePacket.getLength()); sentence = sentence.replace("clientmessage:", "");
sentence = sentence.replace("clientmessage:", ""); String ResponseMsg = datahandler.getResponseMsg(sentence, "", stanfordCoreNLP, stanfordCoreNLPSentiment,
String ResponseMsg = datahandler.getResponseMsg(sentence, "", stanfordCoreNLP, stanfordCoreNLPSentiment, true);
true); byte[] sendData = new byte[0];
byte[] sendData = new byte[0]; try {
try { sendData = ResponseMsg.getBytes("UTF-8");
sendData = ResponseMsg.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) {
} catch (UnsupportedEncodingException e) { e.printStackTrace();
e.printStackTrace(); }
} int deliver_port = 0;
int deliver_port = 0; switch (port) {
switch (port) { case 48475:
case 48475: deliver_port = 48470;
deliver_port = 48470; break;
break; case 48476:
case 48476: deliver_port = 48471;
deliver_port = 48471; break;
break; case 48477:
case 48477: deliver_port = 48472;
deliver_port = 48472; break;
break; case 48478:
case 48478: deliver_port = 48473;
deliver_port = 48473; break;
break; }
} DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, ipAddress, deliver_port);
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, ipAddress, deliver_port); try {
try { serverSocket.send(sendPacket);
serverSocket.send(sendPacket); } catch (IOException e) {
} catch (IOException e) { e.printStackTrace();
e.printStackTrace(); }
}
}).start();
} }
} }

View File

@ -44,14 +44,18 @@ public class DiscordHandler extends ListenerAdapter {
stanfordCoreNLPSentiment = datahandler.shiftReduceParserInitiate(); stanfordCoreNLPSentiment = datahandler.shiftReduceParserInitiate();
System.out.println("FINISHED ALL ANNOTATIONS"); System.out.println("FINISHED ALL ANNOTATIONS");
System.out.println("updatedstring cache");
String strF = datahandler.trimString("abcdef"); String strF = datahandler.trimString("abcdef");
datahandler.getResponseFutures(strF, stanfordCoreNLP, stanfordCoreNLPSentiment); datahandler.getResponseFutures(strF, stanfordCoreNLP, stanfordCoreNLPSentiment);
String token = new settings().getDiscordToken(); String token = new settings().getDiscordToken();
JDABuilder.createLight(token, GatewayIntent.GUILD_MESSAGES, GatewayIntent.DIRECT_MESSAGES)
.addEventListeners(new DiscordHandler()) try {
.setActivity(Activity.playing("Being the autism bot")) JDABuilder.createLight(token, GatewayIntent.GUILD_MESSAGES, GatewayIntent.DIRECT_MESSAGES)
.build(); .addEventListeners(new DiscordHandler())
.setActivity(Activity.playing("Being the autism bot"))
.build();
} catch (LoginException e) {
throw new RuntimeException(e);
}
ArrayList<Integer> ports = new ArrayList<Integer>(); ArrayList<Integer> ports = new ArrayList<Integer>();
ports.add(48475); ports.add(48475);
@ -59,10 +63,13 @@ public class DiscordHandler extends ListenerAdapter {
ports.add(48477); ports.add(48477);
ports.add(48478); ports.add(48478);
for (Integer port : ports) { for (Integer port : ports) {
new ThreadClient(port, datahandler, stanfordCoreNLP, stanfordCoreNLPSentiment); new Thread(() -> {
new ThreadClient(port, datahandler, stanfordCoreNLP, stanfordCoreNLPSentiment);
}).start();
} }
} }
@Override @Override
public void onMessageReceived(MessageReceivedEvent event) { public void onMessageReceived(MessageReceivedEvent event) {
String content = event.getMessage().getContentRaw(); String content = event.getMessage().getContentRaw();