FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
uploadFile/testUploadFile/Listenner.m at master · codeguesser/uploadFile · GitHub
codeguesser
uploadFile
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
uploadFile
/
testUploadFile
/
Listenner.m
Copy path
More file actions
More file actions
Latest commit
History
History
History
84 lines (59 loc) · 2.03 KB
Breadcrumbs
uploadFile
/
testUploadFile
/
Listenner.m
Copy path
File metadata and controls
84 lines (59 loc) · 2.03 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
//
SendMessageButton.m
//
NetServer
//
//
Created by on 2012/5/23.
//
Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
#
import
"
Listenner.h
"
@implementation
Listenner
@synthesize
delegate=_delegate;
- (
id
)
init
{
self = [
super
init
];
if
(self) {
[
NSThread
detachNewThreadSelector:
@selector
(
connectThread
)
toTarget:
self
withObject:
nil
];
}
return
self;
}
-(
void
)
connectThread
{
NSThread
*subThreed = [
NSThread
currentThread
];
NSAutoreleasePool
*uploadPool = [[
NSAutoreleasePool
alloc
]
init
];
NSLog
(
@"
thread start
"
);
if
((sock_fd=
socket
(
AF_INET
,
SOCK_STREAM
,
0
))== -
1
) {
NSLog
(
@"
socket create error
"
);
}
my_addr.
sin_family
=
AF_INET
;
my_addr.
sin_port
=
htons
(
SERVERPORT
);
my_addr.
sin_addr
.
s_addr
=
INADDR_ANY
;
bzero
(&(my_addr.
sin_zero
),
8
);
if
(
bind
(sock_fd, (
struct
sockaddr *)&my_addr,
sizeof
(
struct
sockaddr))== -
1
) {
NSLog
(
@"
bind error
"
);
}
if
(
listen
(sock_fd,
BACKLOG
)==-
1
) {
NSLog
(
@"
listen error
"
);
}
while
(
YES
) {
socklen_t
sin_size =
sizeof
(
struct
sockaddr_in);
if
((client_fd =
accept
(sock_fd, (
struct
sockaddr *)&remote_addr, &sin_size))==-
1
) {
NSLog
(
@"
accept error
"
);
continue
;
}
//
NSLog(@"remote ip is %s,and it want the msg",inet_ntoa(remote_addr.sin_addr));
if
((recvbytes=
recv
(client_fd, buf,
200
,
0
))==-
1
) {
NSLog
(
@"
recv error
"
);
}
buf[recvbytes]=
'
\0
'
;
NSString
*getString = [
NSString
stringWithFormat:
@"
%s
"
,buf];
[
self
performSelectorOnMainThread:
@selector
(
returnMessage:
)
withObject:
getString
waitUntilDone:
YES
];
}
[[
NSRunLoop
currentRunLoop
]
runMode:
NSDefaultRunLoopMode
beforeDate:
[
NSDate
distantFuture
]];
[uploadPool
release
];
uploadPool =
nil
;
subThreed =
nil
;
NSLog
(
@"
thread over
"
);
}
-(
void
)
returnMessage
:
(
NSString
*)
getString
{
[
self
.delegate
getMessage:
getString];
}
@end
Back
|
FazBrowse Home
|
New Git URL