B4J Question Print to Network IP

marco.canta

Active Member
Licensed User
Longtime User
Hi, I need to print data to a printer connected to the network and with an IP address.
I made programs that use USB printers, but never on the net with IP ... I don't know where to start.
Any tutorials or suggestions?

Thank you
Marco
 

Peter Simpson

Expert
Licensed User
Longtime User
Thanks jahswani,
your suggestion has been very useful to me.

I take it that you got it working then, as it's only a few lines of code???
 
Upvote 0

marco.canta

Active Member
Licensed User
Longtime User
my code for Test Print


B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form

    Dim CustomPrinter As Socket                         
    Dim AStreams As AsyncStreams
    
    Private btnPrint As Button
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show

    CustomPrinter.Initialize("CustomPrinter")
    CustomPrinter.Connect("192.168.1.81", 9100, 0)             '192.168.1.81=Printer address, 9100=Port number (please look up port number)
End Sub

Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub btnPrint_MouseClicked (EventData As MouseEvent)
    Dim SendMsg As String
    SendMsg = "Hello World !!!"                             'Send this line to the EPSON printer
    AStreams.Write(SendMsg.GetBytes("UTF8"))
    AStreams.Write(("" & Chr(10)).GetBytes("UTF8"))
End Sub

Sub CustomPrinter_Connected (Successful As Boolean)
    Log("Connecterd : " & Successful)
    If Successful Then
        AStreams.Initialize(CustomPrinter.InputStream, CustomPrinter.OutputStream, "AStreams")
    End If
End Sub
 
Upvote 0
Top