Skip to content

Commit 0e6ad42

Browse files
committed
小修小改
1 parent abb7672 commit 0e6ad42

File tree

3 files changed

+59
-27
lines changed

3 files changed

+59
-27
lines changed

CrawlPandaDanmu/.idea/workspace.xml

Lines changed: 43 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CrawlPandaDanmu/src/main/java/Crawl.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import java.io.IOException;
88
import java.io.OutputStream;
99
import java.net.Socket;
10-
import java.util.Arrays;
1110
import java.util.List;
1211

1312
/**
@@ -37,6 +36,7 @@ public class Crawl extends Thread {
3736
* @throws IOException
3837
*/
3938
public boolean init() throws IOException {
39+
System.out.println("获取登录信息");
4040
String roomId = Utils.getRoomId();
4141
String time = String.valueOf(System.currentTimeMillis());
4242

@@ -103,7 +103,7 @@ public boolean init() throws IOException {
103103
*/
104104
public void login() throws IOException {
105105
socket = new Socket(serverIp,port);
106-
System.out.println("连接弹幕服务器:" + serverIp + ":" + port);
106+
System.out.println("登录弹幕服务器:" + serverIp + ":" + port);
107107
ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
108108
byte[] b = new byte[]{0x00, 0x06, 0x00, 0x02, 0x00, 0x61};
109109
byteArray.write(b);
@@ -124,12 +124,16 @@ public void login() throws IOException {
124124

125125
@Override
126126
public void run() {
127-
MessageHandler messageHandler;
127+
MessageHandler messageHandler = null;
128128
OutputStream outputStream;
129129

130130
try {
131-
init();
131+
//初始化失败
132+
if (!init()) {
133+
return;
134+
}
132135
login();
136+
System.out.println("----------------------------");
133137

134138
messageHandler = new MessageHandler(socket);
135139
outputStream = socket.getOutputStream();
@@ -160,6 +164,12 @@ public void run() {
160164
e.printStackTrace();
161165
} catch (InterruptedException e) {
162166
e.printStackTrace();
167+
} finally {
168+
try {
169+
messageHandler.close();
170+
} catch (IOException e) {
171+
e.printStackTrace();
172+
}
163173
}
164174
}
165175
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#要抓取的斗鱼房间网址
2-
roomId = 88911
1+
#要抓取的熊猫房间ID
2+
roomId = 224588

0 commit comments

Comments
 (0)