背景

客户内网环境需要通过vpn连接,vpn只有windows版本,我工作用的都是mac,导致每次要连个vpn都得开虚拟机,而且很多开发软件在windows中没有替代品,导致开发效率很低,总之就是各种不方便,后面才知道windows自带端口转发工具,试用了下效果还不错。

实现

比如对方系统地址http://192.168.25.1:7001,你在虚拟机里设置端口转发到该系统后,就可以使用虚拟机地址进行访问。用管理员打开命令行窗口,输入以下命令

Read the rest of this entry

背景

weblogic admin server端口号7001,在启动的时候,能启动成功,但是无法访问,错误日志里有Address already in use的错误信息,这个错误信息的意思是7001端口号被占用。

你需要了解的

网卡

服务器可能有多张网卡,并且有一张默认的网卡,叫做回环网卡,名称默认一般是lo,ip地址为127.0.0.1,这个网卡不是一个硬件设备而是由软件实现,所有发送到该网卡的数据能够立即被接收,提高本地应用程序通信效率,所以如果你在一台服务器上既部署了你的应用程序也部署了数据库,那么用localhost或者127.0.0.1作为连接地址是最快的。

Read the rest of this entry

为了研究tcp连接建立过程,用java编写了一个tcp客户端(client),一个tcp服务端(Server)。程序的逻辑很简单,client连接server,向server发送消息,server收到消息作出响应,如果发送的消息是”close”字符串,双方关闭连接。

用抓包工具wireshark进行抓包,分析整个通信过程。

server

public class TcpServer {
    private final int SERVER_PORT = 8001;
    private ServerSocket servSocket;
    private Socket socket;
    public static void main(String[] args) throws Exception {
        TcpServer server = new TcpServer();
        server.acceptRequest();
    }
    /**
     * 接收客户端请求
     *
     * @throws Exception
     */
    public void acceptRequest() throws Exception {
        servSocket = new ServerSocket(SERVER_PORT);
        while (true) {
            System.out.println("准备接受请求....");
            socket = servSocket.accept();
            System.out.println("接收来自" + socket.getInetAddress().getHostName() + "的请求");
            while (true) {
                try {
                    InputStream in = socket.getInputStream();
                    int size;
                    byte[] msg = new byte[1024];
                    ByteArrayOutputStream bout = new ByteArrayOutputStream();
                    size = in.read(msg);
                    if (size == -1) {
                        System.out.println("关闭连接:" + socket.getInetAddress());
                        socket.close();
                        break;
                    }
                    bout.write(msg, 0, size);
                    String content = bout.toString();
                    bout.close();
                    System.out.println("接收到的报文为:");
                    System.out.println(content);
                    String response = "recived message:" + content;
                    socket.getOutputStream().write(response.getBytes("utf-8"));
                    socket.getOutputStream().flush();
                    System.out.println("报文已发送,等待接收");
                } catch (Exception ex) {
                    ex.printStackTrace();
                    socket.close();
                    break;
                }
            }
        }
    }
}

Read the rest of this entry

,