Sign up to create your own snipts, or login.

Public snipts » frusdelion's snipts The latest snipts from frusdelion.

showing 1-3 of 3 snipts
  • Issue with vertical-align. temporarily using propietary browser elements.
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <style>
    #wrapper {
    	display:inline;
    	vertical-align:middle;
    	width:100%;
    	height:100%;
    }
    
    #container {
    	margin:auto;
    	height:465px;
    	width:960px;
    	-moz-box-shadow:0 1px 10px #777;
    	-moz-border-radius:10px;
    }
    </style>
    </head>
    
    <body>
    <div id="wrapper">
    <div id="container">
    </div>
    </div>
    </body>
    </html>
    

    copy | embed

    0 comments - tagged in  posted by frusdelion on Dec 23, 2009 at 9:06 a.m. EST
  • A new Multiuser Sockets Thingy
    <?php 
    // Set time limit to indefinite execution 
    set_time_limit (0); 
    
    // Set the ip and port we will listen on 
    $address = '2.0.0.5'; 
    $port = 9000; 
    $max_clients = 10; 
    
    // Array that will hold client information 
    $clients = Array(); 
    
    // Create a TCP Stream socket 
    $sock = socket_create(AF_INET, SOCK_STREAM, 0); 
    // Bind the socket to an address/port 
    socket_bind($sock, $address, $port) or die('Could not bind to address'); 
    // Start listening for connections 
    socket_listen($sock); 
    
    // Loop continuously 
    while (true) { 
        // Setup clients listen socket for reading 
        $read[0] = $sock; 
        for ($i = 0; $i < $max_clients; $i++) 
        { 
            if ($client[$i]['sock']  != null) 
                $read[$i + 1] = $client[$i]['sock'] ; 
        } 
    	//$ready = socket_select('lol', null, null, null,null);
        /* if a new connection is being made add it to the client array */ 
        if (in_array($sock, $read)) { 
            for ($i = 0; $i < $max_clients; $i++) 
            { 
                if ($client[$i]['sock'] == null) { 
                    $client[$i]['sock'] = socket_accept($sock); 
                    break; 
                } 
                elseif ($i == $max_clients - 1) 
                    print ("too many clients");
            } 
            if (--$ready <= 0) 
                continue; 
        } // end if in_array 
         
        // If a client is trying to write - handle it now 
        for ($i = 0; $i < $max_clients; $i++) // for each client 
        { 
            if (in_array($client[$i]['sock'] , $read)) 
            { 
                $input = socket_read($client[$i]['sock'] , 1024); 
                if ($input == null) { 
                    // Zero length string meaning disconnected 
                    unset($client[$i]); 
                } 
                $n = trim($input); 
                if ($input == 'exit') { 
                    // requested disconnect 
                    socket_close($client[$i]['sock']); 
                } elseif ($input) { 
                    // strip white spaces and write back to user 
                    $output = ereg_replace("[ \t\n\r]","",$input).chr(0); 
                    socket_write($client[$i]['sock'],$output); 
                } 
            } else { 
                // Close the socket 
                socket_close($client[$i]['sock']); 
                unset($client[$i]); 
            } 
        } 
    } // end while 
    // Close the master sockets 
    socket_close($sock); 
    ?>
    

    copy | embed

    0 comments - tagged in  posted by frusdelion on May 19, 2009 at 5:26 a.m. EDT
  • TCP Sockets PHP Thingy
    <?php
    // define  TCP port & local host
    $port=65535;
    $host='2.0.0.5';
    set_time_limit(0);
    // create low level socket
    if(!$socket=socket_create(AF_INET,SOCK_STREAM,0)){
        trigger_error('Error creating new socket',E_USER_ERROR);
    }
    // tie up socket to TCP port
    if(!socket_bind($socket,$host,$port)){
        trigger_error('Error binding socket to TCP
    port',E_USER_ERROR);
    }
    // begin listening connections
    if(!socket_listen($socket)){
        trigger_error('Error listening socket
    connections',E_USER_ERROR);
    }
    // create communication socket
    if(!$comSocket=socket_accept($socket)){
        trigger_error('Error creating communication
    socket',E_USER_ERROR);
    }
    $message='This is a simple TCP/IP server created with PHP
    sockets!'."\r\n";
    socket_write($comSocket,$message,strlen($message));
    // start a loop and continue reading user input
    do{
        // delay loop execution
        // read socket input
        $socketInput=socket_read($comSocket,1024,1);
        if(trim($socketInput)!=''){         
            // if user did not entered the 'STOP" command continuereading data
            if(trim($socketInput)!='STOP'){
                // build socket output 
                $socketOutput='The string you entered was '.$socketInput."\r\n";
                // write data back to socket server
                socket_write($comSocket,$socketOutput,strlen($socketOutput));
                echo $socketOutput;
            }
            else{
                // if 'STOP' command was entered close communicationsocket & terminate all the connections
                socket_close($comSocket);
                break;
            }
        }
    }
    while(true);
    // close global socket
    socket_close($socket);
    ?>
    

    copy | embed

    0 comments - tagged in  posted by frusdelion on May 19, 2009 at 5:17 a.m. EDT
Sign up to create your own snipts, or login.