-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSender.m
More file actions
45 lines (34 loc) · 1013 Bytes
/
Sender.m
File metadata and controls
45 lines (34 loc) · 1013 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//
// GetMessage.m
// NetClient
//
// Created by on 2012/5/23.
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
#import "Sender.h"
@implementation Sender
-(void)SendMessage{
const char * ipstr = "192.168.1.105";
if ((host = gethostbyname(ipstr))==NULL) {
NSLog(@"host error");
};
//NSLog(@"%s",host->h_name);
if ((sock_fd=socket(AF_INET, SOCK_STREAM, 0))==-1) {
NSLog(@"create socket error");
}
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(SERVERPORT);
server_addr.sin_addr = *((struct in_addr*)host->h_addr);
bzero(&(server_addr.sin_zero), 8);
if (connect(sock_fd, (struct sockaddr *)&server_addr, sizeof(struct sockaddr))==-1) {
perror("connect error");
}
if (send(sock_fd, content.UTF8String, 100, 0)==-1) {
NSLog(@"send error");
}
}
-(void)setContent:(NSString *)_content{
[content release];
content = [_content retain];
}
@end