当前位置:编程学习 > JSP >>

serversocket 堵塞

 

 

救命 救命

服务器端 

 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];
    补充:Jsp教程,Java基础

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,