HabboxWiki needs you!
Are you a Habbo buff? Or maybe a rare trader with a bunch of LTDs? Get involved with HabboxWiki to share your knowledge!
Join our team!
Whether you're raving for rares, excited for events or happy helping, there's something for you! Click here to apply
Need a helping hand?
Check out our guides for all things to help you make friends, make rooms, and make money!


Results 1 to 9 of 9

Thread: PHP Script

  1. #1
    Join Date
    Dec 2007
    Posts
    2,807
    Tokens
    0

    Latest Awards:

    Default PHP Script

    I've followed a tutorial to create a socket server in PHP however I am getting the following error:
    Parse error: syntax error, unexpected T_NS_SEPARATOR, expecting T_STRING in /Applications/XAMPP/xamppfiles/htdocs/script.php on line 9
    Heres my code:
    PHP Code:
    <?

    $host 
    "127.0.0.1";
    $port 6932;

    set_time_limit(0);

    $socket socket_create(AF_INETSOCK_STREAM0) or die("Could not create socket\n");

    $result socket_bind($socket$host$port) or die("Could not bind to socket\n");

    $result socket_listen($socket3) or die("Could not set up socket listener\n");

    $spawn socket_accept($socket) or die("Could not accept incoming connection\n");

    $input socket_read($spawn1024) or die("Could not read input\n");

    $input trim($input);

    $output strrev($input) . "\n";
    socket_write($spawn$outputstrlen ($output)) or die("Could not write output\n");

    socket_close($spawn);
    socket_close($socket);
    ?>
    Any help would be greatly appreciated!

  2. #2
    Join Date
    Jun 2008
    Location
    England, On a beach somewhere
    Posts
    2,483
    Tokens
    691

    Latest Awards:

    Default

    Are you sure the ip is correct or online?

  3. #3
    Join Date
    Dec 2007
    Posts
    2,807
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Mickword View Post
    Are you sure the ip is correct or online?
    Yep, it's the IP of your own computer and if I visit it I get the Xampp logo like I should.

  4. #4
    Join Date
    Nov 2007
    Posts
    1,253
    Tokens
    150

    Latest Awards:

    Default

    Worked great for me? Made a small C# app (based on online examples) to send data to it as well.

    PHP:

    PHP Code:
    <?php
    // Binding Info
    $host "127.0.0.1";
    $port 7684;

    // Unlimited Script Running
    set_time_limit(0);

    // Open Sockets
    $socket socket_create(AF_INETSOCK_STREAM0);
    $result socket_bind($socket$host$port);
    $result socket_listen($socket3);
    $spawn socket_accept($socket);

    // Infinate Loop
    while( )
    {
        
    $input = @socket_read($spawn1024) or exit;
        
    $input trim($input);

        
    $output "Recieved \n";
        
    socket_write($spawn$outputstrlen ($output)) or die("Could not write output\n");

        echo 
    $input '<br>';
        
        
    ob_flush();
    }
    ?>
    C#:

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Net;
    using System.Net.Sockets;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                TcpClient svConn = new TcpClient();
                Console.WriteLine("Establishing connection to PHP socket server...");
    
                svConn.Connect("127.0.0.1", 7684);
    
                Console.WriteLine("Connected");
                Console.WriteLine("Enter string/command to be sent:");
    
                while (true)
                {
                    String message = Console.ReadLine();
                    Stream svStream = svConn.GetStream();
    
                    ASCIIEncoding asciiMessage = new ASCIIEncoding();
                    byte[] asciiMessageBytes = asciiMessage.GetBytes(message);
    
                    svStream.Write(asciiMessageBytes, 0, asciiMessageBytes.Length);
    
                    byte[] response = new byte[100];
                    int responseBytes = svStream.Read(response, 0, 100);
    
                    for (int i = 0; i < responseBytes; i++)
                    {
                        Console.Write(Convert.ToChar(response[i]));
                    }
                }
            }
        }
    }
    and screencast showing it working

    http://screencast.com/t/OWE5MTk5Y2

  5. #5
    Join Date
    Jun 2005
    Posts
    4,795
    Tokens
    0

    Latest Awards:

    Default

    Are you using php 5.3 by any chance?

  6. #6
    Join Date
    Nov 2007
    Posts
    1,253
    Tokens
    150

    Latest Awards:

    Default

    In my example, although I am pretty sure it was directed at FlyDuo, I was using 5.3.0 with the sockets extension enabled (obviously).

  7. #7
    Join Date
    Dec 2007
    Posts
    2,807
    Tokens
    0

    Latest Awards:

    Default

    I'm using the latest XAMPP on Snow Leopard with just the defaults. On yours it doesn't load until you start the client, on mine it loads instantly and says the below so I don't have time to even start the client.
    Parse error: syntax error, unexpected T_NS_SEPARATOR, expecting T_STRING in /Applications/XAMPP/xamppfiles/htdocs/test.php on line 10
    Is there maybe something extra I need to enable?

    Its PHP version 5.2.12
    Last edited by MrPinkPanther; 05-01-2010 at 06:48 PM.

  8. #8
    Join Date
    Nov 2007
    Posts
    1,253
    Tokens
    150

    Latest Awards:

    Default

    I'm sure it would output a different error, but is the sockets extension enabled?

  9. #9
    Join Date
    Dec 2007
    Posts
    2,807
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Source View Post
    I'm sure it would output a different error, but is the sockets extension enabled?
    It is unfortunately. It's uncommented in php.ini

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •