FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ShadePE/src/raklib/server/UDPServerSocket.php at master · ExplodingPE/ShadePE · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
ExplodingPE
/
ShadePE
Public
forked from
sftpocketmine/SpigotPE
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
ShadePE
/
src
/
raklib
/
server
/
UDPServerSocket.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
97 lines (83 loc) · 2.7 KB
Breadcrumbs
ShadePE
/
src
/
raklib
/
server
/
UDPServerSocket.php
Copy path
File metadata and controls
97 lines (83 loc) · 2.7 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace
raklib
\
server
;
class
UDPServerSocket{
/** @var \Logger */
protected
$
logger
;
protected
$
socket
;
public
function
__construct
(
\
ThreadedLogger
$
logger
,
$
port
=
19132
,
$
interface
=
"
0.0.0.0
"
){
$
this
->
socket
=
socket_create
(
AF_INET
,
SOCK_DGRAM
,
SOL_UDP
);
//socket_set_option($this->socket, SOL_SOCKET, SO_BROADCAST, 1); //Allow sending broadcast messages
if
(@
socket_bind
(
$
this
->
socket
,
$
interface
,
$
port
) ===
true
){
socket_set_option
(
$
this
->
socket
,
SOL_SOCKET
,
SO_REUSEADDR
,
0
);
$
this
->
setSendBuffer
(
1024
*
1024
*
8
)->
setRecvBuffer
(
1024
*
1024
*
8
);
}
else
{
$
logger
->
critical
(
"
**** FAILED TO BIND TO
"
.
$
interface
.
"
:
"
.
$
port
.
"
!
"
,
true
,
true
,
0
);
$
logger
->
critical
(
"
Perhaps a server is already running on that port?
"
,
true
,
true
,
0
);
exit
(
1
);
}
socket_set_nonblock
(
$
this
->
socket
);
}
public
function
getSocket
(){
return
$
this
->
socket
;
}
public
function
close
(){
socket_close
(
$
this
->
socket
);
}
/**
* @param string &$buffer
* @param string &$source
* @param int &$port
*
* @return int
*/
public
function
readPacket
(&
$
buffer
, &
$
source
, &
$
port
){
return
socket_recvfrom
(
$
this
->
socket
,
$
buffer
,
65535
,
0
,
$
source
,
$
port
);
}
/**
* @param string $buffer
* @param string $dest
* @param int $port
*
* @return int
*/
public
function
writePacket
(
$
buffer
,
$
dest
,
$
port
){
return
socket_sendto
(
$
this
->
socket
,
$
buffer
,
strlen
(
$
buffer
),
0
,
$
dest
,
$
port
);
}
/**
* @param int $size
*
* @return $this
*/
public
function
setSendBuffer
(
$
size
){
@
socket_set_option
(
$
this
->
socket
,
SOL_SOCKET
,
SO_SNDBUF
,
$
size
);
return
$
this
;
}
/**
* @param int $size
*
* @return $this
*/
public
function
setRecvBuffer
(
$
size
){
@
socket_set_option
(
$
this
->
socket
,
SOL_SOCKET
,
SO_RCVBUF
,
$
size
);
return
$
this
;
}
}
?>
Back
|
FazBrowse Home
|
New Git URL