Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-22-2009, 05:28 PM   #1 (permalink)
ustech
 
Join Date: Jan 2009
Posts: 42
Default send files over socket connection

-- want to send files to iphone over socket connection/wifi; so downloaded ASyncSocket which generates plenty of build errors related to Jam deprecated.

... trying to connect to my c++ windows socket software -- which works fine between to windows machines over port 8686.

I got this code from this forum, which so far does nada, but eventually goes to NSStreamEventErrorOccurred in the debugger:

So which port do I use? -- tried 2222; 3258; 60000; and 8686
Make the iphone the client or the server?

So how to implement sending files over a socket connection to the iphone?


- (IBAction)sendCommandid)sender {


NSHost *host = [NSHost hostWithAddress:@"10.21.1.105"];
if (host != nil)
{
// iStream and oStream are instance variables
[NSStream getStreamsToHost:host port:8686 inputStream:&iStream outputStream:&oStream]; //was 2222; 3258; 60000; nada

//iStream is instance var of NSSInputStream
[iStream retain];
[iStream setDelegate:self];
[iStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[iStream open];

//oStream is instance var of NSSOutputStream
[oStream retain];
[oStream setDelegate:self];
[oStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[oStream open];

NSError *streamError;
streamError = [iStream streamError];
streamError = [oStream streamError];

NSStreamStatus streamStatus;
streamStatus = [iStream streamStatus];
streamStatus = [oStream streamStatus];
}
}



- (void)streamNSStream *)theStream handleEventNSStreamEvent)streamEvent
{
NSString *io;
NSString *resultText;

if (theStream == iStream) io = @">>";
else io = @"<<";

NSString *eventx;
switch (streamEvent)
{
case NSStreamEventNone:
eventx = @"NSStreamEventNone";
//resultText.font = [UIFont fontWithName:@"Helvetica" size:10.0];
//resultText.textColor = [UIColor whiteColor];
resultText = [[NSString alloc] initWithFormat: @"Can not connect to the host!"];
break;
case NSStreamEventOpenCompleted:
eventx = @"NSStreamEventOpenCompleted";
break;
case NSStreamEventHasBytesAvailable:
eventx = @"NSStreamEventHasBytesAvailable";
if (theStream == iStream)
{
uint8_t buffer[1024];
int len;
while ([iStream hasBytesAvailable])
{
len = [iStream read:buffer maxLength:sizeof(buffer)];
if (len > 0)
{
NSString *output = [[NSString alloc] initWithBytes:buffer length:len encoding:NSASCIIStringEncoding];
NSData *theData = [[NSData alloc] initWithBytes:buffer length:len];
if (nil != output)
{
NSArray *arr = [output componentsSeparatedByString:@"\n"];

//resultText.font = [UIFont fontWithName:@"Helvetica" size:10.0];
//resultText.textColor = [UIColor whiteColor];
resultText = [[NSString alloc] initWithFormat: @"%@\n%@", resultText, output];
NSLog(@"%@", output);
[output release];
}
}
}
}
break;
case NSStreamEventHasSpaceAvailable:
eventx = @"NSStreamEventHasSpaceAvailable";

break;
case NSStreamEventErrorOccurred:
eventx = @"NSStreamEventErrorOccurred";
//resultText.font = [UIFont fontWithName:@"Helvetica" size:10.0];
//resultText.textColor = [UIColor whiteColor];
resultText = [[NSString alloc] initWithFormat: @"Can not connect to the host!"];
break;
case NSStreamEventEndEncountered:
eventx = @"NSStreamEventEndEncountered";
[theStream close];
[theStream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[theStream release];
theStream = nil;

break;
default:
eventx = @"** Unknown";
}

NSLog(@"%@ : %@", io, eventx);
}
ustech001 is offline   Reply With Quote
Old 04-22-2009, 08:41 PM   #2 (permalink)
Former NeXTStep Developer
 
Join Date: Mar 2009
Posts: 997
Default

I'm sorry, what was the question?

joe
FlyingDiver is offline   Reply With Quote
Old 04-23-2009, 07:38 PM   #3 (permalink)
ustech
 
Join Date: Jan 2009
Posts: 42
Default Hi

Hi FlyingDiver! I was just thinking about trying to implement your code this morning -- funny you've answered my post.

Looks like you're connecting to a Telnet session...

http://www.iphonedevsdk.com/forum/ip...onnection.html

Your post says 'here's 95% of the code' -- so I'm trying to figure out if

(a) I can get import ASyncSocket.h and get your code up-and-running
(b) If I can connect to my videophone software and send files over the socket connection
(c) Which port to use?

You can download my eMail VideoPhone from mediaclubroyale.com -- it can send files over a socket connection. So, if you want to try connecting to my VideoPhone software -- and send a file to the iphone, I'll send you an unlock code to my software -- email me or click contact from the website. (otherwise -- it will work as a 30 day demo)
ustech001 is offline   Reply With Quote
Old 04-23-2009, 11:19 PM   #4 (permalink)
Former NeXTStep Developer
 
Join Date: Mar 2009
Posts: 997
Default

Quote:
Originally Posted by ustech001 View Post
(a) I can get import ASyncSocket.h and get your code up-and-running
Maybe. I don't remember what else I left out from what I posted, but it wasn't much.

Quote:
(b) If I can connect to my videophone software and send files over the socket connection
Sending data back and forth should work. Files is going to take defining some protocol to mark beginning/end of the files.

Quote:
(c) Which port to use?
Shouldn't matter, if it's an outgoing connection to your server (as you can see when I'm connecting to the telnet port). If you want inbound connections, it'll have to be a port higher than 1024, as the lower ones require root privileges (I think).


Quote:
You can download my eMail VideoPhone from mediaclubroyale.com -- it can send files over a socket connection. So, if you want to try connecting to my VideoPhone software -- and send a file to the iphone, I'll send you an unlock code to my software -- email me or click contact from the website. (otherwise -- it will work as a 30 day demo)
I might take a look. No promises.

joe
FlyingDiver is offline   Reply With Quote
Old 04-24-2009, 02:03 AM   #5 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: San Diego, CA
Posts: 406
Default

Hint: you aren't going to find the Prime Minister at #2 Downing Street.

Ok, serious answer... you've got a server answering on port 8086. Your remote app had best be a client, connecting to port 8086.
jtara is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 421
9 members and 412 guests
AppleSteve, banatary70, chiataytuday, DaveDee, Domele, ilmman, Jameswhitfield, johnRambo, Objective Zero
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 157,854
Threads: 88,915
Posts: 379,298
Top Poster: BrianSlick (7,072)
Welcome to our newest member, Jameswhitfield
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:37 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0