Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Can't open socket - Co może być źle?
PGmajster
post 17.08.2013, 20:26:49
Post #1





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 27.02.2013

Ostrzeżenie: (0%)
-----


Witam, tworzę na zamówienie sklep, nie jest to mój pierwszy, lecz przy tym pojawił się błąd
Cytat
Can't open socket.


A dokładnie:

Cytat
Warning: fsockopen() [function.fsockopen]: unable to connect to 37.59.6.133:9999 (Connection refused) in ŚCIEŻKA/rcon.php on line 31
Can't open socket.


A linijką 31 jest:

Kod
if( $this->Socket = FSockOpen( $Ip, (int)$Port ) )


No i tutaj jest problem, nie wiem co w tej linijce jest źle (myślę, że wszystko jest git).

Zameiszcze jeszcze w spoilerze cały kod pliku rcon.php


CODE
<?php
class MinecraftRconException extends Exception
{
// Exception thrown by MinecraftRcon class
}

class MinecraftRcon
{

//
const SERVERDATA_EXECCOMMAND = 2;
const SERVERDATA_AUTH = 3;

//
const SERVERDATA_RESPONSE_VALUE = 0;
const SERVERDATA_AUTH_RESPONSE = 2;

private $Socket;
private $RequestId;

public function __destruct( )
{
$this->Disconnect( );
}

public function Connect( $Ip, $Port = 25575, $Password, $Timeout = 3 )
{
$this->RequestId = 0;

if( $this->Socket = FSockOpen( $Ip, (int)$Port ) )
{
Socket_Set_TimeOut( $this->Socket, $Timeout );

if( !$this->Auth( $Password ) )
{
$this->Disconnect( );

throw new MinecraftRconException( "Nie mozna sie polaczyc ( serwer jest wlaczony ? )" );
}
}
else
{
throw new MinecraftRconException( "Can't open socket." );
}
}

public function Disconnect( )
{
if( $this->Socket )
{
FClose( $this->Socket );

$this->Socket = null;
}
}

public function Command( $String )
{
if( !$this->WriteData( self :: SERVERDATA_EXECCOMMAND, $String ) )
{
return false;
}

$Data = $this->ReadData( );

if( $Data[ 'RequestId' ] < 1 || $Data[ 'Response' ] != self :: SERVERDATA_RESPONSE_VALUE )
{
return false;
}

return $Data[ 'String' ];
}

private function Auth( $Password )
{
if( !$this->WriteData( self :: SERVERDATA_AUTH, $Password ) )
{
return false;
}

$Data = $this->ReadData( );

return $Data[ 'RequestId' ] > -1 && $Data[ 'Response' ] == self :: SERVERDATA_AUTH_RESPONSE;
}

private function ReadData( )
{
$Packet = Array( );

$Size = FRead( $this->Socket, 4 );
$Size = UnPack( 'V1Size', $Size );
$Size = $Size[ 'Size' ];

// TODO: Add multiple packets (Source)

$Packet = FRead( $this->Socket, $Size );
$Packet = UnPack( 'V1RequestId/V1Response/a*String/a*String2', $Packet );

return $Packet;
}

private function WriteData( $Command, $String = "" )
{
// Pack the packet together
$Data = Pack( 'VV', $this->RequestId++, $Command ) . $String . "\x00\x00\x00";

// Prepend packet length
$Data = Pack( 'V', StrLen( $Data ) ) . $Data;

$Length = StrLen( $Data );

return $Length === FWrite( $this->Socket, $Data, $Length );
}
}



Z góry dziękuje za pomoc! Pozdrawiam smile.gif

Go to the top of the page
+Quote Post
Dominator
post 17.08.2013, 20:40:31
Post #2





Grupa: Zarejestrowani
Postów: 565
Pomógł: 15
Dołączył: 11.10.2010

Ostrzeżenie: (20%)
X----


Też się zajmuję pisaniem sklepu (itemshopu). Prawdopodobnie serwer nie jest włączony.
Go to the top of the page
+Quote Post
PGmajster
post 17.08.2013, 21:00:20
Post #3





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 27.02.2013

Ostrzeżenie: (0%)
-----


Jest włączony, port rcon jest dobry, bo przed chwilą zmieniałem na 9999 smile.gif
Hasło również zmieniałem i wpisywałem nowe.
Go to the top of the page
+Quote Post
Dominator
post 17.08.2013, 21:01:59
Post #4





Grupa: Zarejestrowani
Postów: 565
Pomógł: 15
Dołączył: 11.10.2010

Ostrzeżenie: (20%)
X----


Zmień port rcona na 25575 i zobacz czy zadziała.
Go to the top of the page
+Quote Post
PGmajster
post 18.08.2013, 09:10:07
Post #5





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 27.02.2013

Ostrzeżenie: (0%)
-----


Dalej występuje ten problem...
To nie pierwszy mój sklep, który robię, ale z nim tylko mam problemy...
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 26.04.2024 - 05:28