[CDRIVER-108] getaddrinfo not working Created: 18/Jan/12 Updated: 19/Oct/16 Resolved: 20/Jan/12 |
|
| Status: | Closed |
| Project: | C Driver |
| Component/s: | None |
| Affects Version/s: | 0.4 |
| Fix Version/s: | 0.5 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | natalie po | Assignee: | Kyle Banker |
| Resolution: | Done | Votes: | 0 |
| Labels: | mongolab | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
C, Cocoa/iOS |
||
| Description |
|
Hi there, I'd like to use the mongo-c-driver in a new iOS project, and I'm following the tutorial (http://api.mongodb.org/c/current/tutorial.html), but I can't successfully connect to a mongolab.com database of my creation. I can connect to the mongolab db at the command line ("mongo ds029807.mongolab.com:29807/starwatch_1", for example), so I know it exists. I've tried several variations of ip and port declarations such as the following (in objective-C) and it compiles and runs successfully, but it does not connect to my mongolab db: mongo conn[1]; NSString * ip = @"ds029807.mongolab.com"; int status = mongo_connect(conn, (char*)ip, port); if( status != MONGO_OK ) { ... }... more code below The conn->err value is always MONGO_CONN_FAIL, even if I append the ":1234" port number at the end of the ip string, or other ways. Have you connected to a mongolab collection with this library before? Could you give me guidance on how the syntax would work, or if I'm barking up the wrong tree? Googling the topic didn't shed any light on the subject. I've worked successfully with perl and python mongo libraries with mongolab, and I'm hoping I can do the same in C/Objective-C. Thank you! |
| Comments |
| Comment by Kyle Banker [ 20/Jan/12 ] |
|
You're welcome! |
| Comment by natalie po [ 19/Jan/12 ] |
|
Great! I've confirmed that this works for me in a simple C script. Now I just need to work on linking the right files in my iOS project. Thanks very much, Kyle! |
| Comment by Kyle Banker [ 19/Jan/12 ] |
|
Yes. Here's a basic test script: https://gist.github.com/55ed6c59d9deb3a7f49b Here's how I compile the library: Here's how I compile the test script: |
| Comment by natalie po [ 19/Jan/12 ] |
|
Thanks, Kyle, for taking a look. I'm still not having luck connecting to my mongolab db. As a sanity check, is this along the same lines of the syntax you're using? mongo conn[1]; int status = mongo_connect(conn, ip, port_num); My connection result still results in failure (-1). Thanks again for helping with this! |
| Comment by Kyle Banker [ 19/Jan/12 ] |
|
I've just pushed a small fix, and I tested it with a MongoLab database, and it worked! Please let me know if you have any problems with it. |
| Comment by Kyle Banker [ 19/Jan/12 ] |
|
Thanks, Natalie. Will commit a fix later this afternoon. |
| Comment by natalie po [ 18/Jan/12 ] |
|
Thanks, Kyle, for the fast response! I've got the code from the latest release (commit: 879b67c40a6d2ee284c7a99b13ded8b1b6535109), and I ran scons to rebuild the files. My project now includes the net.* files that include comments about the Linux version, and I removed the other net.* files from my project (since they borked on methods being declared twice, as expected). I'm stepping through the following call in my project's debugger: int status = mongo_connect(conn, "ds029807.mongolab.com", 29807); and here's my rough stack trace of where it's failing (adding arrows for hopefully easier indentations and reading): mongo.c - mongo_connect(): Thanks again for taking a close look at this! |
| Comment by Kyle Banker [ 18/Jan/12 ] |
|
I need to make a new release, but you're probably running into an issue resolving the host name. Please checkout from head (i.e., the latest commit). Then compile like so: scons --use-platform=LINUX You'll then have the libraries you need. Do no append the port number to the host name. |