Star-Dust Expert Licensed User Longtime User Jan 18, 2021 #1 I am using the iNetwork library to receive connections from external clients. B4X: Copy Do While True Serv.Listen Wait For Serv_NewConnection (Successful As Boolean, NewSocket As Socket) If Successful Then astream.Initialize(NewSocket.InputStream,NewSocke.OutputStream,"astream") log("ip") End If Loop But I would like to know the IP address of the clients, what can I do?
I am using the iNetwork library to receive connections from external clients. B4X: Copy Do While True Serv.Listen Wait For Serv_NewConnection (Successful As Boolean, NewSocket As Socket) If Successful Then astream.Initialize(NewSocket.InputStream,NewSocke.OutputStream,"astream") log("ip") End If Loop But I would like to know the IP address of the clients, what can I do?
Erel B4X founder Staff member Licensed User Longtime User Jan 18, 2021 #2 Try this: Code: Copy Dim no As NativeObject = NewSocket Dim host As String = no.GetField("socket").GetField("host").AsString Upvote 0
Try this: Code: Copy Dim no As NativeObject = NewSocket Dim host As String = no.GetField("socket").GetField("host").AsString
Star-Dust Expert Licensed User Longtime User Jan 18, 2021 #3 Raise an error B4X: Copy Application_Start Application_Active Error occurred on line: 29 (HttpServer) Object was not initialized (NSObject) Stack Trace: ( CoreFoundation <redacted> + 252 libobjc.A.dylib objc_exception_throw + 56 CoreFoundation <redacted> + 0 B4i Example -[B4IObjectWrapper object] + 136 B4i Example -[B4INativeObject AsString] + 76 CoreFoundation <redacted> + 144 CoreFoundation <redacted> + 292 B4i Example +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1608 B4i Example -[B4IShell runMethod:] + 448 B4i Example -[B4IShell raiseEventImpl:method:args::] + 1648 B4i Example -[B4IShellBI raiseEvent:event:params:] + 1580 B4i Example -[B4IDebugResumableSub resume::] + 356 B4i Example -[B4I checkAndRunWaitForEvent:event:params:] + 516 B4i Example -[B4IShellBI raiseEvent:event:params:] + 1436 B4i Example __50-[B4I raiseEventFromDifferentThread:event:params:]_block_invoke + 60 libdispatch.dylib <redacted> + 24 libdispatch.dylib <redacted> + 16 libdispatch.dylib <redacted> + 1068 CoreFoundation <redacted> + 12 CoreFoundation <redacted> + 1924 CoreFoundation CFRunLoopRunSpecific + 436 GraphicsServices GSEventRunModal + 104 UIKitCore UIApplicationMain + 212 B4i Example main + 124 libdyld.dylib <redacted> + 4 ) Upvote 0
Raise an error B4X: Copy Application_Start Application_Active Error occurred on line: 29 (HttpServer) Object was not initialized (NSObject) Stack Trace: ( CoreFoundation <redacted> + 252 libobjc.A.dylib objc_exception_throw + 56 CoreFoundation <redacted> + 0 B4i Example -[B4IObjectWrapper object] + 136 B4i Example -[B4INativeObject AsString] + 76 CoreFoundation <redacted> + 144 CoreFoundation <redacted> + 292 B4i Example +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1608 B4i Example -[B4IShell runMethod:] + 448 B4i Example -[B4IShell raiseEventImpl:method:args::] + 1648 B4i Example -[B4IShellBI raiseEvent:event:params:] + 1580 B4i Example -[B4IDebugResumableSub resume::] + 356 B4i Example -[B4I checkAndRunWaitForEvent:event:params:] + 516 B4i Example -[B4IShellBI raiseEvent:event:params:] + 1436 B4i Example __50-[B4I raiseEventFromDifferentThread:event:params:]_block_invoke + 60 libdispatch.dylib <redacted> + 24 libdispatch.dylib <redacted> + 16 libdispatch.dylib <redacted> + 1068 CoreFoundation <redacted> + 12 CoreFoundation <redacted> + 1924 CoreFoundation CFRunLoopRunSpecific + 436 GraphicsServices GSEventRunModal + 104 UIKitCore UIApplicationMain + 212 B4i Example main + 124 libdyld.dylib <redacted> + 4 )
Erel B4X founder Staff member Licensed User Longtime User Jan 18, 2021 #4 I see. The remote address is not kept when ServerSocket accepts a new connection. It is currently not possible to get this information. Upvote 0
I see. The remote address is not kept when ServerSocket accepts a new connection. It is currently not possible to get this information.
Star-Dust Expert Licensed User Longtime User Jan 21, 2021 #6 Is there another way to get it? Because in some contexts it is really necessary Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Jan 21, 2021 #8 Maybe in a few minutes... Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Jan 21, 2021 #9 I've updated the library. You can now get the host and port: Code: Copy Sub Server_NewConnection (Successful As Boolean, NewSocket As Socket) Dim no As NativeObject = NewSocket Log(no.GetField("socket").GetField("host").AsString) Log(no.GetField("socket").GetField("port").AsString) End Sub The updated internal library will be included in the next version of B4i. It was already uploaded to the hosted builders. Upvote 0
I've updated the library. You can now get the host and port: Code: Copy Sub Server_NewConnection (Successful As Boolean, NewSocket As Socket) Dim no As NativeObject = NewSocket Log(no.GetField("socket").GetField("host").AsString) Log(no.GetField("socket").GetField("port").AsString) End Sub The updated internal library will be included in the next version of B4i. It was already uploaded to the hosted builders.
Star-Dust Expert Licensed User Longtime User Jan 21, 2021 #10 It works properly. Many thanks, it was very helpful to me. Upvote 0