Android Question Get PORT of HTTP GET - HTTP Server

Licht2002

Member
Licensed User
Longtime User
Hello Experts...

is it possible to get the PORT of a HTTP-Request GET?

With the following Code i only get the IP:

B4X:
Sub Server_HandleRequest (Request As ServletRequest, Response As ServletResponse)

            Case Request.RequestURI.Contains("23446554861/holeIP")
                Log("/holeIP   : " & Request.RequestURI )
                [B]Log("from IP   : " & Request.RemoteAddress)[/B]
                Dim RA  = ( Request.RemoteAddress) As String
                Response.SendString(RA)
                Log(Request.Method)
......

With the UDP-Lib Packet5000.port is it possible - why not with HTTP Server.

Thx

Tom
 

drgottjr

Expert
Licensed User
Longtime User
are you referring to the server's local port or the requester's local port? i ask because i think you're mistaken about the udp.port method. it refers to the server's listening port. the same information is available in the jserver library.

if, on the other hand, you mean the requester's local port, things get a little tricky. this information is available when the requester's connection is "accepted". when this occurs, a socket is created for the communication between the server and the requester. part of that socket is the requester's ip address and the port (normally chosen at random) for communication received from the server.

with jserver, that socket is passed to the thread handler. i've looked through the jserver library some. the underlying socket mechanism does not appear to be exposed. i don't see how you can determine the client's port with the library. in some systems (probably not on a non-rooted android device), there are ways of determing socket connections. at the lowest level, connections are handled with sockets. if you were writing a server, determining who was on which ports would be easy. jserver reflects a higher level. perhaps someone with more time might find a way of accessing the actual socket created when the server accepts a connection from the requester.
 
Upvote 0
Top