3

I am trying to connect to a TCP socket on a Windows XP machine using the computer name from an iPad.

I've tried using:

getaddrinfo(hostName, 4097, &hints, &res0);

This fails when hostName = "MyHost" and succeeds when hostName = "192.168.0.4"

I've tried using AsynchSockets with the same results using:

[mySocket connectToHost:hostName onPort:4097 error:nil];

The XP machines do just fine connecting using: Winsock.RemoteHost = "MyHost" for VB and MySocket->Connect("MyHost", 4097); for C++

How do I do something similar on the iPad using Xcode?

Bo Persson
  • 86,087
  • 31
  • 138
  • 198
schaz
  • 825
  • 2
  • 9
  • 12

2 Answers2

1

You're going to need an SMB client library for iOS. Here's a place to start:

http://38leinad.wordpress.com/2011/03/23/windows-filesharing-library-for-ios/

Flyingdiver
  • 2,122
  • 13
  • 18
  • I downloaded the Tango SMB client library for iOS and found the function address_for_host(). It uses the deprecated function gethostbyname().\n When I called it with "10.0.0.4" it returned 0x4000000a and when I called it with "MyHost" it returned INADDR_NONE (0xffffffff) Any other suggestions? Thanks – schaz Aug 23 '11 at 01:15
0

If it works with direct IP and doesn't with a hostName 'MyHost' this most probably means that 'MyHost' isn't getting resolved (to an IP) on iPad. For example: there's a file called hosts (usually c:\windows\system32\drivers\etc\hosts) on an XP machine - where a host name like MyHost can have it's IP defined.

A line "192.168.0.4 MyHost" would do just that.

It seems you can't edit hosts file on non-jailbroken iPad: Can I edit an iPad's host file?

But here you can find a way around this.

Community
  • 1
  • 1
Rok Jarc
  • 18,235
  • 9
  • 64
  • 120