1

when use GCDWebServer(iOS), I want to request 2 urls like: 192.168.0.121/sample, 192.168.0.121/sample2 with same port like 8080. But one success, one failed.I know port been occupied, but how to aviod it?

this is my demo, thx for downing... https://github.com/liman123/MockServer_demo

I have read all README and checked the sample app,but still can not find solution, can some one help me? (Let GCDWebServer support different paths with same port), thank u!

  • Make sure to read the README, header documentation, and review the sample apps, before asking questions. Such basic usage of GCDWebServer is documented in depth. – Pol Sep 11 '15 at 09:57
  • I have read all README and checked the sample app,but still can not find solution, can u help me (Let GCDWebServer support different paths with same port), thank u! –  Sep 11 '15 at 10:54
  • If this is what your are trying to do, you cannot have 2 GCDWebServer instances running in the same port. You must use one and install multiple handlers as shown in the README and examples. – Pol Sep 11 '15 at 15:35
  • yes! I have successed, thank u ! –  Sep 12 '15 at 02:23
  • Great, I made it a real answer then. Please accept. – Pol Sep 12 '15 at 21:06

2 Answers2

2

Do it with different handlers where you define your path e.g. like this:

    [_webServer addHandlerForMethod:@"GET"
                          path:@"/path/one"
                  requestClass:[GCDWebServerRequest class]
                  processBlock:^GCDWebServerResponse *(GCDWebServerRequest* request) {

                      GCDWebServerDataResponse* response = [GCDWebServerDataResponse responseWithHTML:@"<html><body><p>Hello World</p></body></html>"];
                      return response;

                  }];

And second one could look like this:

    [_webServer addHandlerForMethod:@"GET"
                          path:@"/path/two"
                  requestClass:[GCDWebServerRequest class]
                  processBlock:^GCDWebServerResponse *(GCDWebServerRequest* request) {

                      GCDWebServerDataResponse* response = [GCDWebServerDataResponse responseWithHTML:@"<html><body><p>Hello a second time</p></body></html>"];
                      return response;

                  }];

Examples at: https://github.com/swisspol/GCDWebServer

Mexx
  • 359
  • 3
  • 17
0

You cannot have 2 GCDWebServer instances running in the same port. You must use one and install multiple handlers as shown in the README and examples.

Pol
  • 3,848
  • 1
  • 38
  • 55