SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot annimal's Avatar
    Join Date
    May 2004
    Location
    london
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking php noob question

    hello all this is my first post hope its not to lame!

    dose any one know how i can use this string in php its from a java p2p client i want to put it into my php P2P client
    Code:
     public void sendChatMessage(String message) throws IOException {
    	sendCommand("<"+myself.getNick()+">",message);
        }
    it looks kined of right already but i want to attach it to a submit button dose any one have any ideas or insite on how to convert this to a php string or attach it to a submit button#

    thanks for your time hope some one can help

  2. #2
    SitePoint Addict yjanse's Avatar
    Join Date
    Apr 2004
    Location
    The Netherlands
    Posts
    240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    function sendChatMessage($message) {
       
    sendCommand"<" $this->getNick ">"$message);

    This would be valid PHP, but doesn't support exceptions of course.
    What you probably want to do is create an HTML form which posts the message and nickname to the server where a PHP script parses that data and does something with it, like putting it in a database.

    You can however do nothing with that function you show us there if you don't have a halfway decent design and base of the client you want to make.
    Also, are you sure you want to use PHP for a client? Remember that PHP is not particularly interactive, and executions end when the page is loaded.

    Tell us some more about your design. Perhaps we can help.
    Last edited by yjanse; May 26, 2004 at 05:54.

  3. #3
    SitePoint Zealot annimal's Avatar
    Join Date
    May 2004
    Location
    london
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ty ty

    Thanx for your help on that!

    I do have a half decent client made to log in to the chat server its just missing a few functions.
    using php to make the client is proving to be a bit of a problem as most of my send receve vars are on a loop back so ive striped down to bare Hand shake protocol im going to use that to refer all the functions to
    i.e inclued_once socket.php as the raw protocol!

    im hoping this will work lol.

    and thanx again for your imput its verry much apretiated man.

  4. #4
    SitePoint Zealot annimal's Avatar
    Join Date
    May 2004
    Location
    london
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The hole design is based on a p2p Direct connect client.
    i.e a bot.The origonal code logged into a hub and returned $search Hub $nicklist the problem was it is.

    there is a send function that sends the handshake $myinfo [nick] [pass] this logs the phpdc client in
    im trying to wright a function that will search from my client and send text to the hub! As i say ive striped it down to just the basic login witch uses a config.php a class.php and phpdcmain.php im not sure wether to put the functions in the class file and require_once!
    this is my over all Problem

  5. #5
    SitePoint Addict yjanse's Avatar
    Join Date
    Apr 2004
    Location
    The Netherlands
    Posts
    240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Something like this?

    phpdcmain.php
    PHP Code:
    <?php 
    // Access the configuration set in config.php
    if(file_exists('config.php')) { 
     require_once(
    'config.php');
    } else {
     
    trigger_error('Can not load configuration'E_USER_ERROR);
    }
    // Access the functions that class.php offers.
    if(file_exists('class.php')) { 
     require_once(
    'class.php');
    } else {
     
    trigger_error('Can not load class library'E_USER_ERROR);
    }
    ?>
    The class.php can then also access the configuration settings.

    On a more technical level to get this to actually work, you need to program using sockets which I have never done yet in PHP. There is a bit more information on this over here:
    http://nl3.php.net/manual/en/ref.sockets.php

  6. #6
    SitePoint Zealot annimal's Avatar
    Join Date
    May 2004
    Location
    london
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes i think thats what i need but most of the actualt functions are done in the class file witch calls from the config the $host $nick $port the class file contains the socket like so
    PHP Code:
    <?php

    class PHPDc {

        var 
    $socket;
        var 
    $usesockets;
        var 
    $config;
        var 
    $hub;
        var 
    $state FALSE;
        var 
    $nrconnect 1;




    //-------------------------------
    // Connect to a given host / port
    //-------------------------------

    function connect ($host$port) {

      
    $address gethostbyname($host);

                if(
    array_search('sockets',get_loaded_extensions()) !== FALSE) {
                
                    
    $this->debuglog ("NR Connect : ".$this->nrconnect"\r\n");
                    
    $this->debuglog ("WARNING: your PHP build supports real sockets.");            
                    
    $this->usesockets 1;
                    
    $this->nrconnect++;
                    
                    
    $this->socket socket_create(AF_INETSOCK_STREAM0);
                    
                    if (!
    $this->socket) {

                      
    $this->debuglog ('Failed to create socket '.$adress);
                      
    $this->debuglog ('Error : 'socket_strerror(socket_last_error()) );
                      
    $this->debuglog ('Error NR : 'socket_last_error() );
                      
                    }

                    if (!
    socket_connect($this->socket$address$port)) {

                      
    $this->debuglog ('Failed to connect to '.$adress);
                      
    $this->debuglog ('Error : 'socket_strerror(socket_last_error()) );
                      
    $this->debuglog ('Error NR : 'socket_last_error() );
                      
                    }
                    
    /*
                    if (!socket_set_nonblock ($this->socket)) {

                      $this->debuglog ('Sockets are blocked');
                      $this->debuglog ('Error : '. socket_strerror(socket_last_error()) );
                      $this->debuglog ('Error NR : '. socket_last_error() );
                    }
                    */
                      
    $this->debuglog ('Succesfully connected to '$host .' ('.$address.'), port '.$port);
                    
                    } else {
                
                      
    $this->debuglog ("NR Connect : ".$this->nrconnect"\r\n");
                      
    $this->debuglog ("WARNING: your PHP build doesn't support real sockets.");                
                      
    $this->usesockets 0;
                      
    $this->nrconnect++;
                    
                    if (!
    $this->socket = @pfsockopen ($address $port$errno$errstr30)) {

                      
    $this->debuglog ('Failed to create socket'$errno .', '$errstr);
                    
                    }

                    if (!
    socket_set_blocking ($this->socketFALSE)) {

                      
    $this->debuglog ('Socket Stream is blocked');
                    
                    }
                    
                      
    //socket_set_timeout ($this->socket, 5);
                      
    $this->debuglog ('Succesfully connected to '$host .' ('.$address.'), port '.$port);
                    }
    }


    //-------------
    // Close socket
    //-------------

    function close () {

      if (
    $this->usesockets == 1)       { socket_close($this->socket); }
      else { 
    fclose ($this->socket); }

    }
    function 
    sendChatMessage($message) { 
       
    sendCommand"<" $this->getNick ">"$message); 

    ?>
    the last function is the one that you have desently halped me with i was ondering if i can refrence this function from the maindc.php page used to execute the code

    if you could show me how refer to that function via a submit button that would be cool. feel free to use the socket code .


Bookmarks

Posting Permissions

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