Send/receive a message via TCP IP
Posted: Wed Oct 15, 2008 12:19 pm
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
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
the result is the empty message or maybe the IP 192.168.0.7 cannot retrieve the each of message, I am not understand.
I tried to search the solution at the other forum, but the result is still not resolved.
for the heroes of forum, please help me .... how to solve this problem.
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
Code: Select all
<?
//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);
?>This is my code that running on IP 192.168.0.7
Code: Select all
//RECEIVE MSG THEN INSERT IT INTO A NEW TABLE RECORD
<?php
$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 !";
}
}
?>
I tried to search the solution at the other forum, but the result is still not resolved.
for the heroes of forum, please help me .... how to solve this problem.