updated datagram sockets, had managed to fuck up the port
This commit is contained in:
parent
eb7ed76d2e
commit
10eedf6529
@ -93,7 +93,7 @@ public class DataMapper {
|
||||
ResultSet resultSet = l_pStatement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
int count = resultSet.getInt(1);
|
||||
if (count > 35000) {
|
||||
if (count > 13000) {
|
||||
//System.out.println("cleaning strings: " + l_sSQL);
|
||||
l_pStatement = l_cCon.prepareStatement(l_sSQL);
|
||||
l_pStatement.executeUpdate();
|
||||
|
@ -8,30 +8,28 @@ import java.io.UnsupportedEncodingException;
|
||||
import java.net.*;
|
||||
|
||||
public class ThreadClient {
|
||||
|
||||
|
||||
public ThreadClient(int port, Datahandler datahandler, StanfordCoreNLP stanfordCoreNLP, StanfordCoreNLP stanfordCoreNLPSentiment) {
|
||||
String hostIP = new settings().getHostIP();
|
||||
if (port == new settings().getHostport() || port == new settings().getHostport2()) {
|
||||
hostIP = new settings().getHostIP2();
|
||||
|
||||
try {
|
||||
InetAddress ipAddress = InetAddress.getByName(hostIP);//used ip'
|
||||
try (DatagramSocket serverSocket = new DatagramSocket()) {
|
||||
while (true) {
|
||||
receiveAndSendPacket(serverSocket, ipAddress, port, datahandler, stanfordCoreNLP, stanfordCoreNLPSentiment);
|
||||
}
|
||||
} catch (SocketException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
InetAddress ipAddress = InetAddress.getByName(hostIP);//used ip's
|
||||
try (DatagramSocket serverSocket = new DatagramSocket(port)) {
|
||||
while (true) {
|
||||
receiveAndSendPacket(serverSocket, ipAddress, port, datahandler, stanfordCoreNLP, stanfordCoreNLPSentiment);
|
||||
}
|
||||
} catch (UnknownHostException e) {
|
||||
} catch (SocketException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void receiveAndSendPacket(DatagramSocket serverSocket, InetAddress ipAddress, int port,
|
||||
Datahandler datahandler, StanfordCoreNLP stanfordCoreNLP, StanfordCoreNLP stanfordCoreNLPSentiment) throws
|
||||
IOException {
|
||||
@ -42,39 +40,37 @@ public class ThreadClient {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
new Thread(() -> {
|
||||
String sentence = new String(receivePacket.getData(), 0,
|
||||
receivePacket.getLength());
|
||||
sentence = sentence.replace("clientmessage:", "");
|
||||
String ResponseMsg = datahandler.getResponseMsg(sentence, "", stanfordCoreNLP, stanfordCoreNLPSentiment,
|
||||
true);
|
||||
byte[] sendData = new byte[0];
|
||||
try {
|
||||
sendData = ResponseMsg.getBytes("UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
int deliver_port = 0;
|
||||
switch (port) {
|
||||
case 48475:
|
||||
deliver_port = 48470;
|
||||
break;
|
||||
case 48476:
|
||||
deliver_port = 48471;
|
||||
break;
|
||||
case 48477:
|
||||
deliver_port = 48472;
|
||||
break;
|
||||
case 48478:
|
||||
deliver_port = 48473;
|
||||
break;
|
||||
}
|
||||
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, ipAddress, deliver_port);
|
||||
try {
|
||||
serverSocket.send(sendPacket);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
String sentence = new String(receivePacket.getData(), 0,
|
||||
receivePacket.getLength());
|
||||
sentence = sentence.replace("clientmessage:", "");
|
||||
String ResponseMsg = datahandler.getResponseMsg(sentence, "", stanfordCoreNLP, stanfordCoreNLPSentiment,
|
||||
true);
|
||||
byte[] sendData = new byte[0];
|
||||
try {
|
||||
sendData = ResponseMsg.getBytes("UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
int deliver_port = 0;
|
||||
switch (port) {
|
||||
case 48475:
|
||||
deliver_port = 48470;
|
||||
break;
|
||||
case 48476:
|
||||
deliver_port = 48471;
|
||||
break;
|
||||
case 48477:
|
||||
deliver_port = 48472;
|
||||
break;
|
||||
case 48478:
|
||||
deliver_port = 48473;
|
||||
break;
|
||||
}
|
||||
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, ipAddress, deliver_port);
|
||||
try {
|
||||
serverSocket.send(sendPacket);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -44,14 +44,18 @@ public class DiscordHandler extends ListenerAdapter {
|
||||
stanfordCoreNLPSentiment = datahandler.shiftReduceParserInitiate();
|
||||
|
||||
System.out.println("FINISHED ALL ANNOTATIONS");
|
||||
System.out.println("updatedstring cache");
|
||||
String strF = datahandler.trimString("abcdef");
|
||||
datahandler.getResponseFutures(strF, stanfordCoreNLP, stanfordCoreNLPSentiment);
|
||||
String token = new settings().getDiscordToken();
|
||||
JDABuilder.createLight(token, GatewayIntent.GUILD_MESSAGES, GatewayIntent.DIRECT_MESSAGES)
|
||||
.addEventListeners(new DiscordHandler())
|
||||
.setActivity(Activity.playing("Being the autism bot"))
|
||||
.build();
|
||||
|
||||
try {
|
||||
JDABuilder.createLight(token, GatewayIntent.GUILD_MESSAGES, GatewayIntent.DIRECT_MESSAGES)
|
||||
.addEventListeners(new DiscordHandler())
|
||||
.setActivity(Activity.playing("Being the autism bot"))
|
||||
.build();
|
||||
} catch (LoginException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
ArrayList<Integer> ports = new ArrayList<Integer>();
|
||||
ports.add(48475);
|
||||
@ -59,10 +63,13 @@ public class DiscordHandler extends ListenerAdapter {
|
||||
ports.add(48477);
|
||||
ports.add(48478);
|
||||
for (Integer port : ports) {
|
||||
new ThreadClient(port, datahandler, stanfordCoreNLP, stanfordCoreNLPSentiment);
|
||||
new Thread(() -> {
|
||||
new ThreadClient(port, datahandler, stanfordCoreNLP, stanfordCoreNLPSentiment);
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(MessageReceivedEvent event) {
|
||||
String content = event.getMessage().getContentRaw();
|
||||
|
Loading…
Reference in New Issue
Block a user