Hi,
I wish to use network comms over the local host address (127.0.0.1) for communication with a B4X background task. I can get it working using the IP address that set on the system, but I cannot work out how to get the server to listen on the localhost address.
Here is my code:
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
I had a look at:
Interprocess Comms
But I don't understand it. The attached zip file doesn't have complete projects so I couldn't figure out what the variables were.
I used the Video Tutorial on networking to build my system, but I can't figure out the localhost stuff.
I have attached the client and server projects in the zip.
Could anyone help with this?
Best regards
Rob
			
			I wish to use network comms over the local host address (127.0.0.1) for communication with a B4X background task. I can get it working using the IP address that set on the system, but I cannot work out how to get the server to listen on the localhost address.
Here is my code:
			
				B4X:
			
		
		
		Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI
    Private server As ServerSocket
    Private client As Socket
    Private Astream As AsyncStreams
    Public IsConnected As Boolean
    Private tmr As Timer
    Private lblState As Label
End Sub
'============================================================================================
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("LayoutServer")
    MainForm.Title = "IPC Server"
    MainForm.Show
    listenForConnections
    tmr.Initialize("tmr", 1000)
End Sub
'============================================================================================
private Sub listenForConnections
    server.Initialize(17170, "server")
    Log($"My ip is: ${server.GetMyIP}"$)
    server.Listen
    Wait for server_NewConnection(successful As Boolean, NewSocket As Socket)
    Log("New Connection")
    If successful Then
        If Astream.IsInitialized Then
            Astream.Close
        End If
        Astream.InitializePrefix(NewSocket.InputStream, True, NewSocket.OutputStream, "astream")
        SetState(True)
    End If
End SubI had a look at:
Interprocess Comms
But I don't understand it. The attached zip file doesn't have complete projects so I couldn't figure out what the variables were.
I used the Video Tutorial on networking to build my system, but I can't figure out the localhost stuff.
I have attached the client and server projects in the zip.
Could anyone help with this?
Best regards
Rob
 
				 
 
		 
 
		 
 
		 
 
		 
 
		