Go Back   TheAppleBlog Forums > Apple/Mac > Development
Register Social Groups iSpy Members List Search Today's Posts Mark Forums Read FAQ

Development XCode, Cocoa, and all other development

Reply
 
LinkBack Thread Tools Search this Thread
09-15-2008   #1 (permalink)
Operator
 
Join Date: Sep 2008
Posts: 1
faggus has disabled reputation
i'm having problems with my simple server socket project (no, it's not a school project). when i build this and run it, i don't get any text in the textfields like i'm supposed to, the program just hangs. even with the debugging program it hangs without any errors as well. here's what i got so far:


SocketServer.h

#import <Cocoa/Cocoa.h>
#import <sys/socket.h>
#import <netinet/in.h>
#include <arpa/inet.h>



@interface SocketServer : NSObject {

int serverSocket, sSocket;
struct sockaddr_in socAddress;
int addressSize;
int intPortNumber;


IBOutlet NSTextField *txtReceive;
IBOutlet NSTextField *txtSend;
IBOutlet NSTextField *portNumber;


}

-(IBAction)openServerSocketid)sender;
-(IBAction)closeServerSocketid)sender;
-(IBAction)sendMessageid)sender;

@end



SocketServer.m


#import "SocketServer.h"
#import <sys/socket.h>
#import <netinet/in.h>
#include <arpa/inet.h>
#import <sys/types.h>

#define QUEUE 5

@implementation SocketServer


-(IBAction)openServerSocketid)sender
{
serverSocket = socket (AF_INET, SOCK_STREAM, 0);
addressSize = sizeof (struct sockaddr_in);

if(serverSocket < 0)
{
[txtReceive setStringValue:@"Error opening socket"];
}
else
{
[txtReceive setStringValue:@"Opening Socket..."];
}

socAddress.sin_addr.s_addr = INADDR_ANY;
socAddress.sin_port=htons(5838);
socAddress.sin_family = AF_INET;

if(bind(serverSocket, (struct sockaddr *)&socAddress, sizeof(socAddress)) <0)
{
[txtReceive setStringValue:@"Error binding to port"];
}

getsockname(serverSocket, (struct sockaddr *) &socAddress, (socklen_t *) &addressSize);
[txtReceive setStringValue:@"Opened socket"];

[txtReceive setStringValue:@"Creating listening queue"];

if(listen(serverSocket, QUEUE) <0)
{
[txtReceive setStringValue:@"Error creating listening queue"];
}

for (;
{
sSocket = accept(serverSocket, (struct sockaddr*)&socAddress, (socklen_t *)&addressSize);

}
}




yes, i read beej's guide to network programming and a few other socket explanations. i can't get why it won't open a socket. thanks

Last edited by faggus; 09-16-2008 at 04:25 PM..
faggus is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



All times are GMT -6. The time now is 02:25 PM.




Powered by vBulletin
© 2004-2009

SEO by vBSEO 3.2.0