Android Question Print to IP Adresse

Discussion in 'Android Questions' started by Babo, Jul 13, 2019.

  1. Babo

    Babo New Member Licensed User

    Hello how can i print over the IP Adress? I try this, but it dont work.

    Code:
    #Region  Project Attributes
        
    #ApplicationLabel: B4A Print_on_IP
        
    #VersionCode: 1
        
    #VersionName:
        
    'SupportedOrientations possible values: unspecified, landscape or portrait.
        #SupportedOrientations: unspecified
        
    #CanInstallToExternalStorage: False
    #End Region

    #Region  Activity Attributes
        
    #FullScreen: False
        
    #IncludeTitle: True
    #End Region

    Sub Process_Globals
        
    'These global variables will be declared once when the application starts.
        'These variables can be accessed from all modules.

        
    Dim Socket1 As Socket
        
    Dim Printer1 As TextWriter
    End Sub

    Sub Globals
        
    'These global variables will be redeclared each time the activity is created.
        'These variables can only be accessed from this module.

        
    Private Button1 As Button
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
        
    'Do not forget to load the layout file created with the visual designer. For example:
        'Activity.LoadLayout("Layout1")
        
        
    Activity.LoadLayout("1")
        
        Socket1.Initialize(
    "Socket1")
        Socket1.Connect(
    "192.168.100.202"910020000)
    End Sub

    Sub Activity_Resume

    End Sub

    Sub Activity_Pause (UserClosed As Boolean)

    End Sub

    Sub Socket1_Connected (Successful As Boolean)
        
    If Successful = False Then
            
    Msgbox("Error""")
            
    Return
        
    End If
        
        Printer1.Initialize(Socket1.OutputStream)

        
    Msgbox("Connected""")
    End Sub

    Sub Button1_Click
        Printer1.WriteLine(
    "Testrow")
            
        
    Msgbox("Print""")
    End Sub
     
  2. Babo

    Babo New Member Licensed User

    It is so easy with Java! Is Java the better Way?

    Code:
    try
        {
        
    Socket sock = new Socket("192.168.1.222"9100);
        PrintWriter oStream = new PrintWriter(sock.getOutputStream());
            oStream.println(
    "HI,test from Android Device");
            oStream.println(
    "\n\n\n");
            oStream.close();
            sock.close();
        
    }
        catch (UnknownHostException e)
        {
            e.printStackTrace();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
     
  3. DonManfred

    DonManfred Expert Licensed User

  4. Erel

    Erel Administrator Staff Member Licensed User

    BTW, the Java code you posted is not really valid. You cannot work with network streams on the main thread.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice