schaz
schaz

Reputation: 895

How to connect a TCP socket using a host name on a local network

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?

Upvotes: 3

Views: 3689

Answers (2)

Rok Jarc
Rok Jarc

Reputation: 18875

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.

Upvotes: 0

Flyingdiver
Flyingdiver

Reputation: 2142

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/

Upvotes: 1

Related Questions