import java.net.*;
import java.io.*;
public class URL
{
public static void main (String [] args)
{
String hostname = "localhost";
if(args.length>0)
{
hostname = args[0];
}
PrintWriter out =null;
BufferedReader networkIn = null;
try
{
Socket theSocket = new Socket(hostname,6000 );
networkIn =new BufferedReader(new InputStreamReader(theSocket.getInputStream ()));
BufferedReader userIn = new BufferedReader(new InputStreamReader(System.in));
out =new PrintWriter(theSocket.getOutputStream ());
System.out.println ("connected to echo server");
while(true)
{
String theLine =userIn.readLine ();
if(theLine.equals (".")) break;
out.flush ();
System.out.println (networkIn.readLine());
}
}
catch(IOException ee)
{
System.out.println(ee);
}
finally
{
try
{
if(networkIn != null)
networkIn.close ();
}
catch(IOException ex)
{
}
}
}
}
我是在linux下netbeans环境中运行的,好几个程序都有这样错误,谁帮我运行一下看有没有错误。是不是端口没有打开呀?帮我解释一下,谢谢!
import java.io.*;
public class URL
{
public static void main (String [] args)
{
String hostname = "localhost";
if(args.length>0)
{
hostname = args[0];
}
PrintWriter out =null;
BufferedReader networkIn = null;
try
{
Socket theSocket = new Socket(hostname,6000 );
networkIn =new BufferedReader(new InputStreamReader(theSocket.getInputStream ()));
BufferedReader userIn = new BufferedReader(new InputStreamReader(System.in));
out =new PrintWriter(theSocket.getOutputStream ());
System.out.println ("connected to echo server");
while(true)
{
String theLine =userIn.readLine ();
if(theLine.equals (".")) break;
out.flush ();
System.out.println (networkIn.readLine());
}
}
catch(IOException ee)
{
System.out.println(ee);
}
finally
{
try
{
if(networkIn != null)
networkIn.close ();
}
catch(IOException ex)
{
}
}
}
}
我是在linux下netbeans环境中运行的,好几个程序都有这样错误,谁帮我运行一下看有没有错误。是不是端口没有打开呀?帮我解释一下,谢谢!
用netstat -a在CMD下看看端口有没有打开
不过LINUX的端口打开的也太少了,谁能告诉我怎样打开呀?
客户端发送时服务器端端口可能不对
造成连接的失败
你运行以下你的服务端的jsp程序
将地址写到客户端的submit的action里面就好了