Posts

Showing posts from June, 2015

Php Program to Send a Message from Client(php program) to Server (java program)

What this program does? 1. Make Use of php Socket Programming including with IP address and port number of Server (java program). 2. First starts a server (server.java) which will be always running listening to a port 8080(Server.java) 3. Client (Client.php) sends a number (message) to the server (Sever.java). 4. Server receives this number or messages from Client.php which is run on your Apache server  1. This is Client .php treated as Client which is run on your xampp or wamp server. <?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 .=

Socket Programming using Php

<?php There are only two files are require to execute socket programming . Server .php Client.php This is server.php file .   $host = " 127.0.0.1" ; default ip address for TCP/IP $port = 3306 ; // default port number. // don't timeout! set_time_limit(0); // create socket $socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n"); // bind socket to port $result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n"); // start listening for connections $result = socket_listen($socket, 3) or die("Could not set up socket listener\n"); // accept incoming connections // spawn another socket to handle communication $spawn = socket_accept($socket) or die("Could not accept incoming connection\n"); // read client input $input = socket_read($spawn, 1024) or die("Could not read input\n"); // clean up input string $input = trim($input); echo "Cli