7
7
import java .io .IOException ;
8
8
import java .io .OutputStream ;
9
9
import java .net .Socket ;
10
- import java .util .Arrays ;
11
10
import java .util .List ;
12
11
13
12
/**
@@ -37,6 +36,7 @@ public class Crawl extends Thread {
37
36
* @throws IOException
38
37
*/
39
38
public boolean init () throws IOException {
39
+ System .out .println ("获取登录信息" );
40
40
String roomId = Utils .getRoomId ();
41
41
String time = String .valueOf (System .currentTimeMillis ());
42
42
@@ -103,7 +103,7 @@ public boolean init() throws IOException {
103
103
*/
104
104
public void login () throws IOException {
105
105
socket = new Socket (serverIp ,port );
106
- System .out .println ("连接弹幕服务器 :" + serverIp + ":" + port );
106
+ System .out .println ("登录弹幕服务器 :" + serverIp + ":" + port );
107
107
ByteArrayOutputStream byteArray = new ByteArrayOutputStream ();
108
108
byte [] b = new byte []{0x00 , 0x06 , 0x00 , 0x02 , 0x00 , 0x61 };
109
109
byteArray .write (b );
@@ -124,12 +124,16 @@ public void login() throws IOException {
124
124
125
125
@ Override
126
126
public void run () {
127
- MessageHandler messageHandler ;
127
+ MessageHandler messageHandler = null ;
128
128
OutputStream outputStream ;
129
129
130
130
try {
131
- init ();
131
+ //初始化失败
132
+ if (!init ()) {
133
+ return ;
134
+ }
132
135
login ();
136
+ System .out .println ("----------------------------" );
133
137
134
138
messageHandler = new MessageHandler (socket );
135
139
outputStream = socket .getOutputStream ();
@@ -160,6 +164,12 @@ public void run() {
160
164
e .printStackTrace ();
161
165
} catch (InterruptedException e ) {
162
166
e .printStackTrace ();
167
+ } finally {
168
+ try {
169
+ messageHandler .close ();
170
+ } catch (IOException e ) {
171
+ e .printStackTrace ();
172
+ }
163
173
}
164
174
}
165
175
}
0 commit comments