Php Program to Send a Message from Client(php program) to Server (java program)
What this program does?
<?php
$address = '172.16.50.122'; // java server ip address
$port = 8080; // port number
$socket = socket_create(AF_INET, SOCK_STREAM, getprotobyname('tcp'));
socket_connect($socket, $address, $port);
$message = '<?xml version="1.0"?>';
$message .= '<root>';
$message .= '<attribute-value attribute="sample attribure">';
$message .= '<value>sample value</value>';
$message .= '</attribute-value>';
$message .= '<text>Sample text</text>';
$message .= '</root>';
echo $status = socket_sendto($socket, $message, strlen($message), 0, $address, $port);
if($status !== FALSE)
{
$message = '';
$next = '';
echo $message .= $next;
}
else
{
echo "Failed";
}
socket_close($socket);
?>
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
public class TCPClient {
public static void main(String[] args) throws Exception {
TCPClient myServ = new TCPClient();
myServ.run();
}
public void run() throws Exception {
ServerSocket mySS = new ServerSocket(8080);
Socket SS_accept = mySS.accept();
InputStreamReader mySR = new InputStreamReader(SS_accept.getInputStream());
BufferedReader myBR = new BufferedReader(mySR);
String temp = myBR.readLine();
System.out.println(temp);
}
}
Comments
Post a Comment