-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.php
59 lines (43 loc) · 1.26 KB
/
client.php
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
50
51
52
53
54
55
56
57
58
59
<?php
//if(!($sock = socket_create(AF_INET, SOCK_STREAM, 0)))
//{
// die("Couldn't create socket: [$errorcode] $errormsg \n");
// $errormsg = socket_strerror($errorcode);
// die("Couldn't create socket: [$errorcode] $errormsg \n");
//}
echo "3";
echo "Socket created \n";
//Connect socket to remote server
if(!socket_connect($sock , '74.125.235.20' , 80))
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not connect: [$errorcode] $errormsg \n");
}
echo "Connection established \n";
$message = "GET / HTTP/1.1\r\n\r\n";
//Send the message to the server
if( ! socket_send ( $sock , $message , strlen($message) , 0))
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not send data: [$errorcode] $errormsg \n");
}
echo "Message send successfully \n";
//Now receive reply from server
if(socket_recv ( $sock , $buf , 2045 , MSG_WAITALL ) === FALSE)
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not receive data: [$errorcode] $errormsg \n");
}
//print the received message
echo $buf;
socket_close($sock);
?>
<html>
<head>
</head>
<body>
</body>
</html>