-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsocket.php
More file actions
49 lines (35 loc) · 813 Bytes
/
Copy pathsocket.php
File metadata and controls
49 lines (35 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
if(!isset($_POST))
{
echo "send data";
exit();
}
//get the value
$msg=$_POST['val'];
//create the socket --> ipv4
if(!($sock = socket_create(AF_INET, SOCK_STREAM, 0)))
{
die("Couldn't create socket\n");
}
echo "Socket created \n";
//Connect socket to local ip address
if(!socket_connect($sock , '127.0.0.1' , 5000))
{
die("Could not connect:\n");
}
echo "Connection established \n";
//Send the message to the server
if( ! socket_send ( $sock , $msg , 100 , 0))
{
die("Could not send data\n");
}
echo "Message send successfully \n";
//get response from server
if( ! socket_recv( $sock , $msg , strlen($msg) , 0))
{
die("Could not send data\n");
}
echo "<br/>response : ".$msg;
// close the socket
socket_close($sock);
?>