简体   繁体   English

Java和Android上的套接字编程

[英]Socket programming on java and android

s = new Socket(InetAddress.getByName(server_address), server_port);
out = new PrintWriter(s.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(s.getInputStream()));

...

out.println("DESCRIBE " + url + " RTSP/1.0");
out.println("CSeq: 1");
out.println("");

String answer = null;
try {
    answer = in.readLine();
...

If it happen in java project all good and we get answer like "RTSP/1.0 200 OK\\n", but if I run same code on android I haven't any response. 如果在Java项目中一切正常,我们会得到“ RTSP / 1.0 200 OK \\ n”之类的答案,但是如果我在android上运行相同的代码,则没有任何响应。 Why? 为什么?

Also println() isn't good enough. 另外, println()不够好。 You have to send exactly \\r\\n as line terminators for most Internet protocols, not whatever your local system's line terminator is. 对于大多数Internet协议,您必须完全发送\\ r \\ n作为线路终止符,而不管本地系统的线路终止符是什么。

My guess without you giving any kind of error messages is that you need to add the Internet permission to your app. 我不带任何错误消息的猜测是,您需要向应用程序添加Internet权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM