Jump to content

Search the Community

Showing results for tags 'socket'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start





Website URL








Donation Link

Found 7 results

  1. i have a code in c# and here use GetBytes(msg) for SSlStream.write, here send and received data correctly, here all work fine, now i want to make the same event in php, but here i cant see a SslSteam or similar(i think no problem, becouse i working with socket_connection, and i think SSL is only for security), now for compare i stop the code in c# for see what data is sending and try to convert in php, for send here, i can see a data byte{} in c# and with ` $message=unpack('C*',$message);` i can convert the string to byte[], comparing with c# value is the same so, here all is ok, my problem is when i try to write the request, becouse in SslStream.write accpet byte[] but socket_write no accept whe i try send ` socket_write($socket, '\n', strlen($message))` i have a error : socket_write() expects parameter 2 to be string and obvius is becouse socket_write() only accept string, but so.. as i can send my byte[], becouse the server only accept a byte[] please help me PD> my problem is how i can send the byte[], i dont know if can send eq socket_write($socket, $message[1], strlen($message)), or what is which is the right way, note please $message first is a string as the server only accept byte i use unpack for create a $message[] as byte/integer eq with 70 items, etc, here is ok, becouse comparing with my program in c# give the same value(same array), but now i need send this $message[], but i cant becouse $message now is a byte or integer[], and socket_write only aceppt string, please help me
  2. I am trying to connect to a server socket which will send me a bunch of data after connecting, take a response from me, and then send a bunch more data, repeating this process until it determines its had enough. So basically, after first~ connecting, we will (and currently are) receiving data from the server. We want to take this data, compute it in another script/program passing with AJAX, and then return to this and respond to the server. We're afraid that once we take data from the server, go to compute the data, the socket is going to close and we're not going to be able to continue where we left off. How can we make sure that php persists in its connection to this socket? I've looked into fsockopen and I'm not quite understanding of it and whether it will help here or not. Any assistance? // create socket //$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n"); $socket = fsockopen($host, $port, $errno, $errstr, 30); if (!$socket) { echo "$errstr ($errno)<br />\n"; } $_SESSION['socket'] = $socket; // receive DATA from server //$result = socket_connect($socket, $host, $port) or die("Could not connect to server\n"); echo "Connected to server"; //$_SESSION['connection'] = $result;\ //STOP, PASS DATA, COMPUTE, SEND RESPONSE // send response to server fwrite($socket, $message1) or die("Could not send data to server\n"); // get data server response $result = fread ($socket, 1024) or die("Could not read server response\n"); echo "<br>Reply From Server :".$result; // close socket fclose($socket);
  3. Hi, I am trying to use the LIST command provided by Google for IMAP (as an extension). If I connect to gmail imap from linux telnet and send this command from the console, I get the following result: [#####@#### ~]$ telnet-ssl -z ssl imap.gmail.com 993 Trying Connected to gmail-imap.l.google.com. Escape character is '^]'. * OK Gimap ready for requests from f4if1005730nfh.69 1 LIST "" "*" * LIST (\HasNoChildren) "/" "INBOX" * LIST (\Noselect \HasChildren) "/" "[Gmail]" * LIST (\HasNoChildren \All) "/" "[Gmail]/All Mail" * LIST (\HasNoChildren \Drafts) "/" "[Gmail]/Drafts" * LIST (\HasNoChildren \Important) "/" "[Gmail]/Important" * LIST (\HasNoChildren \Sent) "/" "[Gmail]/Sent Mail" * LIST (\HasNoChildren \Junk) "/" "[Gmail]/Spam" * LIST (\HasNoChildren \Flagged) "/" "[Gmail]/Starred" * LIST (\HasNoChildren \Trash) "/" "[Gmail]/Trash" 1 OK Success If I am sending this command from php, I am receiving only the last line: * OK Gimap ready for requests from e8if455192eeo.69 * CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS COMPRESS=DEFLATE ENABLE MOVE C01 OK ###########@gmail.com ######## authenticated (Success) C02 OK Success My php code is the following: fwrite($fp, "C01 LOGIN username password\r\n"); while ($line = fgets($fp)) { echo $line; $line = preg_split('/\s+/', $line, 0, PREG_SPLIT_NO_EMPTY); $code = $line[0]; if (strtoupper($code) == 'C01') { break; } } fwrite($fp, "C02 LIST '' '*'\r\n"); while ($line2 = fgets($fp)) { echo $line2; $line2 = preg_split('/\s+/', $line2, 0, PREG_SPLIT_NO_EMPTY); $code = $line2[0]; if (strtoupper($code) == 'C02') { break; } } What am I doing wrong? Regards, Tony
  4. Need help on this guys. I'm working on a new project and I'm fairly new on socket connections. Background: I'm creating a PHP script that can receive and store new SMS messages from GSM modem via its API(TCP, request/response way). So far, the manufacturer told me that I should follow this flow on using the device's API: 1. GSM modem sends User Authentication message to Socket Server once a connection is made. 2. Socket Server sends a response. 3. Socket Server waits for incoming connections from GSM. This is my code as of the moment: <?php set_time_limit (0); // Set the ip and port we will listen on $address = ''; $port = 8855; $sock = socket_create(AF_INET, SOCK_STREAM, 0); socket_bind($sock, $address, $port) or die('Could not bind to address'); socket_listen($sock); $client = socket_accept($sock); //Breakdown of received message from GSM modem, I needed the $ID as identifier on my response $length = bin2hex(socket_read($client, 4)); $ID = bin2hex(socket_read($client, 16)); $type = bin2hex(socket_read($client, 4)); $username = bin2hex(socket_read($client, 16)); $password = bin2hex(socket_read($client, 16)); //This is what I should send on the socket as a response $rlength=pack("H*", "00000001"); $rID=pack("H*", $ID); $rtype=pack("H*","00100000"); $rresult=pack("H*", "00"); $response=$rlength.$rID.$rtype.$rresult; //Write the response on the socket socket_write($client, $response, $strlen($response)); //After sending the data, I should wait for the GSM modem's incoming connection when a new SMS message is received. //Any insights what should I code below? socket_close($client); socket_close($sock); ?>
  5. Hello, I am trying to send some hex bytes to a remote socket to switch off a display. I have a java applet which is able to switch off the display by opening a socket. I have tried creating a socket in php and writing the bytes but its doesn't work. I have captured with wireshark with each program does and the php program sends multiple frames where as the java one just sends one. I have attached both wireshark capture files (remove the .txt suffix) and my php code. I am using a wxbinder with my php code which explains some of the functions. The java applet & source code can be found here http://networktools.sourceforge.net/ Is there any way I can use php to send exactly the same frames / packets as the java applet? If you need any more info please ask Thanks, Dan from networktools.txt from php app.txt php-socket.txt
  6. Note: This is mainly a PHP issue, but the java part is a Bukkit plugin. My TCP Server (made in Java) is one that can send and recieve messages/commands from a client like PuTTy. Everything works perfectly in PuTTy, however when I use a small PHP client I made to test commands, it doesn't recieve the complete output. My PHP is as follows <?php echo '<html><body>'; include('config.php'); $service_port = $_GET['sPort']; $address = $_GET['sIP']; $command = null; $args = null; $api = 0; if (isset($_GET['api'])) { $api = 1; } if (!isset($_GET['sMsg'])) { die('No command given'); } else { $command = trim(strtolower($_GET['sMsg'])); if ($command == null || $command == "") { die('No command given'); } if ((strpos($command, ";")) == false) { /* Args check */ //do nothing, no args } else { $args = explode(";", $command); } } $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if ($socket === false) { die('Failed to create socket'); } $result = socket_connect($socket, $address, $service_port); if ($result === false) { die('Failed to connect to server'); } $messag = $command; $message = $messag."\n"; $out = ''; socket_write($socket, $message, strlen($message)); $resp = ""; while ($out = socket_read($socket, 2048)) { $resp .= $out; } $response = trim($resp); $rep = array("/", "\\", "-", "_", "(", ")", "'", "|", "Welcome! Please input the password.", ","); $stripped = str_replace($rep, "", $response); echo $stripped; socket_close($socket); echo '</body></html>'; ?> and when I send the command /adminsconnected the following Java code is fired by the server if (sent.equalsIgnoreCase("/adminsconnected")) { sendText("0", true); plugin.log.info("adminsConnected"); } public void sendText(String text, Boolean suppress) { try { if (suppress) { this.toClient.writeBytes(text + "\r\n"); } else { this.toClient.writeBytes(getTime() + " - "+text + "\r\n"); } if (!suppress) MainClass.log.info("[bTS] Sent: \"" + text + "\""); } catch (Exception e) { e.printStackTrace(); plugin.log.severe(e.toString() + " - sendText (suppress)"); } } My output from PHP is blank, however I recieve the "adminsConnected" and PuTTy gives "0" (the intended output) I get an error in my console: 18:25:53 [sEVERE] java.net.SocketException: Software caused connection abort: socket write error 18:25:53 [sEVERE] at java.net.SocketOutputStream.socketWrite0(Native Method) 18:25:53 [sEVERE] at java.net.SocketOutputStream.socketWrite(Unknown Source) 18:25:53 [sEVERE] at java.net.SocketOutputStream.write(Unknown Source) 18:25:53 [sEVERE] at java.io.DataOutputStream.writeBytes(Unknown Source) 18:25:53 [sEVERE] at com.atrociouss.BTS.Users.sendText(Users.java:339) 18:25:53 [sEVERE] at com.atrociouss.BTS.Users.ssendText(Users.java:323) 18:25:53 [sEVERE] at com.atrociouss.BTS.Users.run(Users.java:278) 18:25:53 [sEVERE] java.net.SocketException: Software caused connection abort: socket write error - sendText (suppress) I was wondering if this was a server issue, or a client issue and if its a mistake that I simply haven't been able to see because i've been staring at it for so long, or if theres something going terribly wrong with my code and I should start from scratch. Any help appreciated!
  7. Hi, I'm trying to access my Gmail account by a socket connection (secure imap is closed by my provider). Currently I'm at this coding state (not very far...): //////////////////////////////////////////// // Open a socket if (!($fp = fsockopen('ssl://imap.gmail.com', 993, $errno, $errstr, 15))) die("Could not connect to host"); // Set timout to 1 second if (!stream_set_timeout($fp, 1)) die("Could not set timeout"); // Fetch first line of response and echo it echo fgets($fp); // Send data to server echo "Writing data..."; fwrite($fp, "C01 CAPABILITY\r\n"); echo " Done\r\n"; // Keep fetching lines until response code is correct while ($line = fgets($fp)) { echo $line; $line = preg_split('/\s+/', $line, 0, PREG_SPLIT_NO_EMPTY); $code = $line[0]; if (strtoupper($code) == 'C01') { break; } } echo "I've finished!"; fclose($fp); //////////////////////////////////////////// Output er følgende: * OK Gimap ready for requests from g8if1416270lbr.32 Writing data... Done * CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 XYZZY SASL-IR AUTH=XOAUTH AUTH=XOAUTH2 C01 OK Thats all she wrote! g8if1416270lbr.32 I've finished! But how do I get IMAP working, hope somebody has some examples / ideas / Morten
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.