Heloo, my php programming is not so good ...
I need help with my problem:
I want to send a raw message from an IP that installed AppServ (Apache, PHP, MySQL packet installation) to a different IP that installed AppServ too
I tried to use this code to send a message first from IP: 192.168.0.1
<?
//SEND MSG
$sock = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$iptarget = "192.168.0.7";
$port=80;
$msg = "192.168.0.1/images/image01.jpg|2008-10-15 23:51:12";
$len = strlen($msg);
if(@socket_sendto($sock, $msg, $len, 0, "$iptarget", 80))
{
echo "$msg = > sent to $iptarget:$port";
}
else
{
echo "$msg = > not sent to $iptarget:$port";
}
@socket_close($sock);
?>
the code above was running successfully, but sometime i see the message is not send. The problem is while retrieving the sent $msg on IP 192.168.0.7 that sent from 192.168.0.1, the $msg was empty. I want to do a mysql_query("INSERT INTO new_msg(msg) VALUES('$msg')"); on IP 192.168.0.7 to save each of message record that will used next time.
This is my code that running on IP 192.168.0.7
<?php
//RECEIVE MSG THEN INSERT IT INTO A NEW TABLE RECORD
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_bind($socket, '192.168.0.7', 80);
$from = "192.168.0.1";
$port = 80;
for($i=1;$i<=10;$i++)
{
if(@socket_recvfrom($socket, $buf, 12, 0, $from, $port))
{
echo "Received $buf from IP $from and port $port" . PHP_EOL;
mysql_query("INSERT INTO new_msg(msg) VALUES('$msg[$i]')");
}
else
{
echo "msg[$i] not received !";
}
}
?>