开发者

how to use NSStream class to create tcp connection iPhone

开发者 https://www.devze.com 2023-03-21 05:56 出处:网络
I need to send a string to a server on the same network with the iPad. when reading This I found out that maybe I need to use the + getStreamsToHost:port:inputStream:outputStream: method but I am not

I need to send a string to a server on the same network with the iPad. when reading This I found out that maybe I need to use the + getStreamsToHost:port:inputStream:outputStream: method but I am not able use it. In 开发者_如何学Pythonxcode I have tried:

//Try 1
NSStream *myStream;
//[myStream getStreamToHost// xcode cant find it]

//Try 2
NSStream *myStream2 = [[NSStream alloc] init];
[myStream2 getStreamToHost// I have initialized it and yet xcode can't find the method


//Try 3
[NSStream getStreamToHost] // does not work eather

 //Try 4
 [[[NSStream alloc] init] getStreamToHost// does not work

and by the way I am listening on port 403 with a simple program called autoit let me show you how:

I have two scripts (the client and the server);

how to use NSStream class to create tcp connection iPhone

first I run the server and it starts listening. Then I run the client script and when that happens a message box appears and a song starts playing:

how to use NSStream class to create tcp connection iPhone

Let me show you the code it is very simple to understand just to show what's going on...

the client code:

how to use NSStream class to create tcp connection iPhone

and the server code:

how to use NSStream class to create tcp connection iPhone

note that the client sends the message hello and when that happens a message box appears MsgBox(0,"Data Received", $TCPReceive) and a song starts playing shellExecute("t.mp3") that mp3 file is on the same directory of the script.

HOW CAN I SEND A SIMILAR MESSAGE BUT WITH AN IPHONE TO MY COMPUTER?


+getStreamsToHost:port:inputStream:outputStream: is a class method (indicated by the +), so you have to use [NSStream getStreams...] instead of [[[NSStream alloc] init] getStreams...].

0

精彩评论

暂无评论...
验证码 换一张
取 消