Hello all ,
I am building a proxy server based on this code
zerver_NewConnection and ast_Newdata were raised but I don't know what next , How should I forward the data received to their direction , get the response and get it back to the connected application ?
Regards
I am building a proxy server based on this code
zerver_NewConnection and ast_Newdata were raised but I don't know what next , How should I forward the data received to their direction , get the response and get it back to the connected application ?
B4X:
#Region Service Attributes
#StartAtBoot: False
#ExcludeFromLibrary: 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 AStreams As AsyncStreams
Dim zerver As ServerSocket
End Sub
Sub Service_Create
'This is the program entry point.
'This is a good place to load resources that are not specific to a single activity.
zerver.Initialize(9030,"zerver" )
Log("Initialized")
zerver.Listen
Log("Listening")
End Sub
Sub Service_Start (StartingIntent As Intent)
Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
End Sub
Sub Service_TaskRemoved
'This event will be raised when the user removes the app from the recent apps list.
End Sub
'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub zerver_NewConnection (Successful As Boolean, NewSocket As Socket)
Log("zerver_NewConnection")
If Successful Then
If AStreams.IsInitialized Then AStreams.Close
AStreams.Initialize( NewSocket.InputStream, NewSocket.OutputStream , "ast") 'initialize AsyncStreamsText with the socket streams.
'
Else
Log(LastException)
End If
zerver.Listen
End Sub
Sub ast_Newdata(buffer() As Byte)
End Sub
Sub ast_Terminated
Log("Connection terminated")
End Sub
Sub Service_Destroy
End Sub
Regards