Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > Coding Releases
You last visited: Today at 03:48

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[PHP] SocksWork - PHP Socket client library

Discussion on [PHP] SocksWork - PHP Socket client library within the Coding Releases forum part of the Coders Den category.

Reply
 
Old   #1
 
manulaiko3.0's Avatar
 
elite*gold: 0
Join Date: May 2014
Posts: 663
Received Thanks: 1,154
[PHP] SocksWork - PHP Socket client library

Hi!

Yesterday night I've made a library to work with sockets, it's called SocksWork.

You can download it from here:


Example code:
Code:
<?php
/**
 * SocksWork example file
 * 
 * This file is made in order to help you understand how SocksWork works
 * First we will instance a SocksWork object and a PacketBuilder object
 * We will use PacketBuilder object to build the packet that will be sent to the server
 * The packet will be like this:
 *         packetID: 1
 *         packetContent: Hello SocksWork!
 * The bytes of packets would be something like this:
 *       PACKET ID  | HELLO SOCKSWORK!
 *    00 00 00 01 00 00 00 16 72 101 108 108 111 32 83 111 99 107 115 87 111 114 107 33
 * The first 4 bytes are packetID:
 *         00 00 00 01 = 1
 * The rest of the packet is the content
 * As the content is just an string first 4 bytes indicates string length:
 *         00 00 00 16 = 16
 * And next bytes are string bytes:
 *         72 101 108 108 111 32 83 111 99 107 115 87 111 114 107 33 = Hello SocksWork!
 * 
 * Once we've sent the packet we will wait for the response
 * Let's assume that the response packet is something like this
 *         packetID = 2
 *         packetContent: Hello!
 * The bytes would be something like this:
 *         PACKET ID  | HELLO!
 *         00 00 00 02 00 00 00 06 72 101 108 108 111 33
 * First 4 bytes are packetID:
 *         00 00 00 02 = 2
 * Next is packet content
 * and as it is just a string we do it like before
 *         00 00 00 06 = 6 (string length)
 *        72 101 108 108 111 33 = Hello!
 * 
 * Ok, let's start!
 */
//Include SocksWork files
require_once '../SocksWork.php';
require_once '../SocksWork/PacketBuilder.php';

//Instance objects
$SocksWork = new SocksWork("localhost", 8080);
$PacketBuilder = new PacketBuilder(1);

//Establish a connection with the server
$SocksWork->connect();

//Build packet
$PacketBuilder->writeStr("Hello SocksWork!");

//Send packet
$SocksWork->send($PacketBuilder);

//Parse response
$PacketBuilder->readStr();

//Get response
$array = $PacketBuilder->getReadBytes();

var_dump($array);

/**
 * It will print something like this:
 * 
 * $array = Array(
 *         [0] => 2;
 *         [1] => "Hello!";
 * )
 * 
 * First index is received packetID
 * and second index is string
 */
Please let me know any kind of bug, I couldn't test it so hope it works.

Manulaiko.
manulaiko3.0 is offline  
Reply


Similar Threads Similar Threads
Suche C++11 / C++ Socket Library
07/25/2013 - C/C++ - 20 Replies
Hallo, wie im Threadtitel zu entnehmen ist, suche ich eine möglichst leicht einzurichtende und möglichst in C++ / C++11 geschriebene Socket Library. Am besten natürlich plattformübergreifend. Die Library sollte eigentlich nur mehrere Clients von mir handhaben können, da ich vor habe einen Clientless Bot zu schreiben. Was könnt ihr mir da empfehlen? Ahja, falls noch jemand eine gute C++ Verschlüsselungs Library kennt mit MD5, immer her damit. :D
Garry's Mod - could not load library client
07/10/2013 - Technical Support - 4 Replies
Hey Liebe Com, ich habe ein Problem mit Garrys Mod. Ich habe es eine Weile nicht gespielt und aufeinmal wenn ich es starten will kommt kurz ein Blackscreen es schließt sich wieder und diesen Fenster/diese Error Meldung erscheint: http://i.epvpimg.com/GezQc.jpg Ich hab es schon 3x Neuinstalliert,Ordner Umbenannt/gelöscht,Auf Fehler Überprüft,Internet durchforstet alles funktioniert nicht. Alle Halflife 2 Teile vorhanden sowie CSS
client.dll init in library client failed
02/07/2012 - Counter-Strike - 5 Replies
Hey Leute, Musste nenn neuen css non steam runterladen, da mein alter mich nicht auf meinen server connecten hat lassen. Jedenfalls jetz kommt immer ENGINE ERROR: client.dll init in library client failed
[C#] Socket Library
03/28/2010 - Coding Releases - 2 Replies
Release Notes: This SocketLibrary (.dll) can be used for any purposes. From something big like a complete MMORPG, to something as small as a chat. I do not really care a bout you giving me credits for this release, but it would be nice if you did. You do not have to believe I made this, if you can prove I didn't create this, please show me. As far as I know, I did create this, didn't take me more than 10 minutes. Version(s): 0.1 - The first release, not many extras yet, just a basic,...



All times are GMT +1. The time now is 03:49.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.