Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8531947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:36:01+00:00 2026-06-11T09:36:01+00:00

How can I operate printer with socket program only. As I tried cups, IPP

  • 0

How can I operate printer with socket program only.
As I tried cups, IPP with php, and printer_open function in windows
but my concerns is not to depend on platform like Linux, window etc.
it should be platform independent.

Below is the code which is creating socket to printer.

Code is not optimized but it is successfully printing the text.
Only problem is that I am unable to check the printing job status.

<?php
$host = "printer_ip";
$port    = 9100; //default listening port for printer
$message = "This text is going to print by printer";
// create socket
$socket = socket_create(AF_INET, SOCK_STREAM, 0);
if(!$socket){
    $errorcode = socket_last_error();
    $errormsg = socket_strerror($errorcode);
    socket_close($socket);
   die("Could not create socket: [$errorcode] $errormsg\n");
}
// connect to server
$result = socket_connect($socket, $host, $port);  
if(!$result){
        $errorcode = socket_last_error();
        $errormsg = socket_strerror($errorcode);
    socket_close($socket);
    die("Could not connect to server: [$errorcode] $errormsg\n");
}
// send string to server
$socket_wrt = socket_write($socket, $message, strlen($message));
if(!$socket_wrt){
    $errorcode = socket_last_error();
    $errormsg = socket_strerror($errorcode);
    socket_close($socket);
    die("Could not send data to server: [$errorcode] $errormsg\n");
}
// get server response
$result = socket_read($socket, 1024);
if(!$result){
    $errorcode = socket_last_error();
    $errormsg = socket_strerror($errorcode);
    socket_close($socket);
    die("Could not read server response: [$errorcode] $errormsg\n");
}
echo "Reply From Server:".$result;
// close socket
socket_close($socket);
?>

EDIT:
This

$result = socket_read($socket, 1024);

is not giving any kind to data.
As printer is idle and no body is using except me, that’s why on every request printer print
the data easily without any connection refuse.
while echo of socket_read response, the concatenated data “Reply from server” also does not print.
Any help will help me lot.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T09:36:02+00:00Added an answer on June 11, 2026 at 9:36 am

    If you can switch from JetDirect (port 9100) to standard LPR, this approach can help you.
    http://www.phpclasses.org/package/2540-PHP-Abstraction-for-printing-documents.html

    originally from:
    printing over network from PHP app

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a function that can operate on both sets and lists and
In Fortran, one can operate on arrays, but how can one treat the indices
I want to develop a Facebook connect application that can operate both inside a
We have a third-party DLL that can operate on a DataTable of source information
I am looking for an embeddable scripting runtime that can operate entirely in memory
HellO, I want to write a binary file format viewer for windows which can
More specifically I want an interface to compare objects which can be only compared
Is there some way I can execute code in the base function for all
http://www.cplusplus.com/reference/algorithm/for_each/ Unary function taking an element in the range as argument. This can either
My question is: are there minimisation algorithms, preferably implemented in Python, that can operate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.