I have been stuck on this for a while now. I am trying to send data to the Java, server with PHP. When i load the plugin in Bukkit, it stops loading when i call this function:
public void SocketListen()
{
String clientSentence;
String capitalizedSentence;
try
{
ServerSocket welcomeSocket = new ServerSocket(25566);
while(true)
{
Socket connectionSocket = welcomeSocket.accept();
BufferedReader inFromClient =
new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
clientSentence = inFromClient.readLine();
System.out.println("Received: " + clientSentence);
capitalizedSentence = clientSentence.toUpperCase() + '
';
outToClient.writeBytes(capitalizedSentence);
}
}
catch(IOException e)
{
getLogger().severe(e.toString());
}
}
which tells me i did something wrong. My PHP is:
<?php
$host = "localhost";
$port = 25566;
$data = 'test
';
if ( ($socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === FALSE )
echo "socket_create() failed: reason: " . socket_strerror(socket_last_error());
else
{
echo "Attempting to connect to '$host' on port '$port'...<br>";
if ( ($result = socket_connect($socket, $host, $port)) === FALSE )
echo "socket_connect() failed. Reason: ($result) " . socket_strerror(socket_last_error($socket));
else {
echo "Sending data...<br>";
socket_write($socket, $data, strlen($data));
echo "OK<br>";
echo "Reading response:<br>";
while ($out = socket_read($socket, 2048)) {
echo $out;
}
}
socket_close($socket);
}
?>
What am i doing wrong?
Basically, i just need the PHP server to send "Hello" then the Java Client Spit it out with getLogger().info(data);
Also, do i need to Port forward 25566 on the Client or the server with PHP? They are both hosted on my Local Network with the same External IP.