一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

serversocket 堵塞

时间:2008-04-28 编辑:简简单单 来源:一聚教程网

 

 

救命 救命

服务器端 

 package web;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;

/**
 *
 * @author Administrator
 */
public class TcpServer {
   
    /** Creates a new instance of TcpServer */
    public TcpServer() {
    }
    public static void main(String[] args){
    ServerSocket svesoc=null;
    Socket soc=null;
    InputStream is=null;
    OutputStream os=null;
    DataInputStream in=null;
    PrintStream out=null;
        try {
            svesoc=new ServerSocket(8000,3);
            svesoc.setSoTimeout(2000000);
            soc=svesoc.accept();
            is=soc.getInputStream();
            os=soc.getOutputStream();
            out=new PrintStream(os);
           
            InetAddress clientIP=soc.getInetAddress();
            System.out.println("Client''s IP address  "+clientIP);
            System.out.println("Client''s port "+soc.getPort());
            out.println("welcome");
            byte[] bmsg=new byte[1024];