package serveraccept;
import java.net.*;
import java.io.*;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/public class ServerAccept implements Runnable {
final static int LISTEN_PORT=8091;
public void run ()
{
ServerSocket server=null;
try {
server =new ServerSocket(LISTEN_PORT);
System.out.println(" now wait for connecting .....");
}
catch (IOException e) {
System.out.println("can not connect to the port :"+LISTEN_PORT+":"+e.getMessage());
System.exit(0);
}
while (true) {
try {
Socket bb=server.accept();////这里是监听
new Thread (new ServerEchoRequest(bb)).start();
// new Thread (new ServerEchoRequest(server.accept())).start();
System.out.println("now start up a connection ");
}
catch (Exception ex) {
System.out.println("Canot recieve data " +ex.getMessage() );
}
} }
public ServerAccept() {
}
public static void main(String[] args) {
// ServerAccept serverAccept1 = new ServerAccept();
// public static void main(String[] args) {
new Thread(new ServerAccept()).start();
} }
import java.net.*;
import java.io.*;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/public class ServerAccept implements Runnable {
final static int LISTEN_PORT=8091;
public void run ()
{
ServerSocket server=null;
try {
server =new ServerSocket(LISTEN_PORT);
System.out.println(" now wait for connecting .....");
}
catch (IOException e) {
System.out.println("can not connect to the port :"+LISTEN_PORT+":"+e.getMessage());
System.exit(0);
}
while (true) {
try {
Socket bb=server.accept();////这里是监听
new Thread (new ServerEchoRequest(bb)).start();
// new Thread (new ServerEchoRequest(server.accept())).start();
System.out.println("now start up a connection ");
}
catch (Exception ex) {
System.out.println("Canot recieve data " +ex.getMessage() );
}
} }
public ServerAccept() {
}
public static void main(String[] args) {
// ServerAccept serverAccept1 = new ServerAccept();
// public static void main(String[] args) {
new Thread(new ServerAccept()).start();
} }
解决方案 »
- 求教!!!急急急!!设计一个GUI界面,实现排序功能
- java -Xmx512m时为什么top看到占用1.6G内存?
- 求助高手:iText里面如何链接文件名含中文的文件?
- JMF
- 欢迎石家庄的java朋友加入改群 33600835 互相学习。。。
- 如何将unicode格式文本解析出 word 用 streamTokenizer?
- JBuilder 2005把含静态方法的类当成变量,识别不出来,怎么办?
- 跪求Oreilly的Java网络编程的中文版电子书,本人不胜感激!
- 我有一个Swing组件(继承了Component类),里面弹出一个对话框,我想控制它在Swing组件的中间而不是屏幕的中间,怎么办?
- 请问大家JBoss的稳定性和效率如何?
- 用JB8编译简单程序,出错,高手救援!!
- 请关注Java中位运算与补码的问题!谢谢!
package serveraccept;
import java.net.*;
import java.io.*;
import java.util.*;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/public class ServerEchoRequest implements Runnable {
Socket m_Socket=null;
final static int MAX_BUFF=4000;
private final static int TIMEOUT=3000;
public ServerEchoRequest (Socket socket) throws SocketException {
m_Socket=socket;
} public void run ()
{
try {
getClient (m_Socket);
}
catch (IOException ex) {
System.out.println(ex);
System.exit(0); }
catch (ClassNotFoundException ex){
System.out.println(ex);
System.exit(0);
}
}
protected void getClient(Socket socket)throws IOException,ClassNotFoundException{
DataInputStream in=new DataInputStream(m_Socket.getInputStream());
String s;
File f=new File("request.txt");
PrintWriter fileout=new PrintWriter(new FileWriter(f));
while ((s=in.readLine())!=null) {
//System.err.println("");
System.out.println(s);
fileout.println(s);
fileout.flush();
}
}/* public static void main(String[] args) {
ServerEchoRequest serverEchoRequest1 = new ServerEchoRequest();
}
*/
}
<html>
<head>
<title>
jsp1
</title>
</head>
<body bgcolor="#ffffff">
<h1>
Display upload file request
</h1>
<form method ="post" action ="http://localhost:8091" enctype="multipart/form-data">
<p> ID:<input type ="text" name ="FileID" size="20" ></p>
<p>file:<input type ="file" name="filedata" size ="20" ></p>
<p><input type="submit" value ="Upload" name="uploadfile"></p>
</form>
</body>
</html>