I am working on a project that uses CocoaHTTPServer and I need to identify clients by either their IP Address or preferably MAC Address. I have to be able to know which device/computer is connecting to the server so that I can track state. I have been looking through the code to see if there is a property on the HTTPConnection, etc. but can't find this information. Is this possible?
method. Due to HTTP pocket (Application layer), it does not contains client IP.
You can subclass HTTPConnection and set the HTTPServer to use your subclass as its connectionClass. Override -(id)initWithAsyncSocket:(GCDAsyncSocket *)newSocket configuration:(HTTPConfig *)aConfig (don't forget to call the superclass's method) and call [newSocket connectedHost] on the passed in GCDAsyncSocket. You can stick the value in an ivar if you need it later, or you can just call [asyncSocket connectedHost] from anywhere else in your subclass.
I wouldn't use this as any sort of identifier, though, as it isn't going to give you very accurate data on who's connecting, as you're likely going to be getting the IP address of the NAT or proxy the user is behind instead, and all clients connecting through a NAT or a proxy will have the same IP address as every other client behind that same NAT or proxy.
On 21 October 2013 at 07:14:50, Dmitry Mikheev (mikhe...@gmail.com) wrote:
Hi Joe,May I kindly ask you to clarify more - how to get MAC address? I understand that it will be available only in localhost. Basically, what I need is to get the MAC address of myself, opening "localhost" page.
Thank You!!!
×ÏÓËÒÅÓÅÎØÅ, 16 ÉÀÎÑ 2013 Ç., 23:38:45 UTC+3 ÐÏÌØÚÏ×ÁÔÅÌØ Joe Francia ÎÁÐÉÓÁÌ:
You can subclass HTTPConnection and set the HTTPServer to use your subclass as its connectionClass. Override -(id)initWithAsyncSocket:(GCDAsyncSocket *)newSocket configuration:(HTTPConfig *)aConfig (don't forget to call the superclass's method) and call [newSocket connectedHost] on the passed in GCDAsyncSocket. You can stick the value in an ivar if you need it later, or you can just call [asyncSocket connectedHost] from anywhere else in your subclass.
I wouldn't use this as any sort of identifier, though, as it isn't going to give you very accurate data on who's connecting, as you're likely going to be getting the IP address of the NAT or proxy the user is behind instead, and all clients connecting through a NAT or a proxy will have the same IP address as every other client behind that same NAT or proxy.
On June 16, 2013 at 2:21:23 AM, Johnny Sung (j7961...@gmail.com) wrote:Hello, I know about TCP/IP is different from HTTP. It's not the same layer in OSI.But my question is: How to get the client public IP when client connected to.In CocoaHTTP, we can get the HTTP request header in- (NSObject<HTTPResponse> *)httpResponseForMethod:(NSString *)method URI:(NSString *)pathmethod. Due to HTTP pocket (Application layer), it does not contains client IP.
I think...I have to catch the client IP when GCDAsyncSocket Accept a connection.But I don't know to do with the code.Can you give me some advices?
--
You received this message because you are subscribed to the Google Groups "CocoaHTTPServer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cocoahttpserv...@googlegroups.com.
To post to this group, send email to cocoaht...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cocoahttpserver/1aeee460-f94f-49b1-aec5-efbe4cef0adb%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.