黑马程序员技术交流社区
标题:
TCp问题
[打印本页]
作者:
画饼
时间:
2013-6-7 16:43
标题:
TCp问题
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
public class TCPdome {
public static void main(String[]args) throws Exception{
ServerSocket Sst =new ServerSocket(8190);
Socket Sk =Sst.accept();
BufferedReader Ips =new BufferedReader(new InputStreamReader(Sk.getInputStream()));
String s ="";
while((s =Ips.readLine())!=null){
System.out.println(s);
}
}
}
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.FileReader;
import java.net.Socket;
public class tcpkh{
public static void main (String[]args) throws Exception{
Socket sck =new Socket("127.0.0.1",8190);
BufferedReader Brd =new BufferedReader(new FileReader("D:\\Java\\src\\com\\bjsxt\\tank\\Tank.java"));
String s =null;
while((s=Brd.readLine())!=null){
DataOutputStream bfs =new DataOutputStream(sck.getOutputStream());
bfs.writeBytes(s);
// bfs.close();
}
// Brd.close();
// sck.close();
}
}
Exception in thread "main" java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.BufferedReader.fill(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at TCPdome.main(TCPdome.java:15)
爆这个错误,请大神帮忙看看
作者:
李润根
时间:
2013-6-7 19:10
把这个 bfs.close(); 放到循环外,试试
作者:
夏一站
时间:
2013-6-7 21:38
加入 private static ServerSocket extracted() throws IOException {
return new ServerSocket(8190);}
package com.hao;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
public class TCPdome {
public static void main(String[]args) throws Exception{
Socket Sk =extracted().accept();
BufferedReader Ips =new BufferedReader(new InputStreamReader(Sk.getInputStream()));
String s ="";
while((s =Ips.readLine())!=null){
System.out.println(s);
}
}
private static ServerSocket extracted() throws IOException {
return new ServerSocket(8190);
}
}
class TCPdome1
{
private static Socket sck;
private static BufferedReader brd;
public static void main (String[]args) throws Exception{
sck = new Socket("127.0.0.1",8190);
brd = new BufferedReader(new FileReader("D:\\Java\\src\\com\\bjsxt\\tank\\Tank.java"));
String s =null;
while((s=brd.readLine())!=null){
DataOutputStream bfs =new DataOutputStream(sck.getOutputStream());
bfs.writeBytes(s);
// bfs.close();
}
// Brd.close();
// sck.close();
}
}
复制代码
你试试看……
作者:
袁梦希
时间:
2013-6-12 18:58
楼主你好 如果问题已经解决 请把帖子的类型改为已解决 然后会给你发几个粽子吃
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2