iOS Question ServerSocket and AddressNewSocket

Star-Dust

Expert
Licensed User
Longtime User
I am using the iNetwork library to receive connections from external clients.

B4X:
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?
 

Star-Dust

Expert
Licensed User
Longtime User
Raise an error
B4X:
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

Star-Dust

Expert
Licensed User
Longtime User
ok. thanks
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
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
I've updated the library.
You can now get the host and port:
B4X:
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

Star-Dust

Expert
Licensed User
Longtime User
It works properly. Many thanks, it was very helpful to me.
 
Upvote 0
Top