서비스를 할때 동시접속자 수에 대한 개념 잡기. 어플리케이션단 튜닝, 하드웨어적 튜닝, 웹서비스의 경우 네트워크 대역폭에
대한 이해, 메모리 상주하는 세션들의 관리의 중요성, db와 커넥션의 갯수, 엔터프라이즈급 서버가 아닌, 로드 밸런싱을 통한
분산 처리(l4스위치등)  등등

http://nimba.tistory.com/entry/%EB%8F%99%EC%8B%9C%EC%A0%91%EC%86%8D%EC%9E%90%EC%88%98-%EC%84%9C%EB%B2%84%EC%9A%A9%EB%9F%89-%EB%A1%9C%EB%93%9C-%EB%B0%B8%EB%9F%B0%EC%8B%B1


l4스위치를 통한 로드밸런싱(포트단위= 독립 프로세스에서의 분산처리)


by givingsheart 2014. 1. 1. 16:24


//자~ 서버 소켓 생성을 쫒아가 봅시다! 포트 번호 받는 생성자~ 

0.서버 소켓의 클래스를 대충 봐야겟네요! 오...SocketImpl ??? 이걸 멤버 필드로 갖고 있네요? 뭘까 뭘까?
 
52 public class ServerSocket implements java.io.Closeable {

56     private boolean created = false;
57     private boolean bound = false;
58     private boolean closed = false;
59     private Object closeLock = new Object();

64     private SocketImpl impl;

69     private boolean oldImpl = false;

}

1.우리가 자주쓰는 포트번호 받는 생성자는 자신의 매개변수 3개짜리 생성자를 호출하는군요?
127    public ServerSocket(int port) throws IOException {
128        this(port, 50, null);
129    }

2.오호~  눈에 띄는게 setImpl()입니다? 추가로 포트 번호, 백로그가 먼진 몰라도 일단 50으로 세팅, 
  저기 237번 라인의 bind()를 잊지 맙시다!!!! 나~중에 다시 봅니다.
229    public More ...ServerSocket(int port, int backlog, InetAddress bindAddr) throws IOException {
230        setImpl();
231        if (port < 0 || port > 0xFFFF)
232            throw new IllegalArgumentException(
233                       "Port value out of range: " + port);
234        if (backlog < 1)
235          backlog = 50;
236        try {
237            bind(new InetSocketAddress(bindAddr, port), backlog);
238        } catch(SecurityException e) {
239            close();
240            throw e;
241        } catch(IOException e) {
242            close();
243            throw e;
244        }
245    }

3.이건 내부 초기화 메서드니까 접근자가 private군요? 
   3.1하여간 팩토리란 객체한테.. createSocketImpl(); 해달라는군요? 
   3.2팩토리 객체 없으면 SockSocketImpl() 객체를 생성하는군요? 소켓소켓? 이름도 희안하네 ㅋㅋㅋ
   3.3위에서 하여간 구현객체가 생성이 되었으니.. 초기화를 해주는군요? impl.setServerSocket(this); 
      일단 메서드 이름대로라면.. 서버소켓을 세팅하는데 매개변수로 자기 자신이 들어갑니다.
282    private void More ...setImpl() {
283        if (factory != null) {
284            impl = factory.createSocketImpl();
285            checkOldImpl();
286        } else {
287            // No need to do a checkOldImpl() here, we know it's an up to date
288            // SocketImpl!
289            impl = new SocksSocketImpl();
290        }
291        if (impl != null)
292            impl.setServerSocket(this);
293    }


4.팩토리는 무시하고 SocksSocketImpl()을 추적해봤습니다. 헐,.. 서버 소켓 생성 했습니다. 휴~


42  class SocksSocketImpl extends PlainSocketImpl implements SocksConsts {
43      private String server = null;
44      private int serverPort = DEFAULT_PORT;
45      private InetSocketAddress external_address;
46      private boolean useV4 = false;
47      private Socket cmdsock = null;
48      private InputStream cmdIn = null;  //오오 많이 보던 인풋스트림 노드계열 클래스! 현재는 비어있지만.. 반갑습니다.
49      private OutputStream cmdOut = null;  //오오 많이 보던 아웃풋스트림 노드계열 클래스!
50      /* true if the Proxy has been set programatically */
51      private boolean applicationSetProxy;  /* false */
52  
53  
54      SocksSocketImpl() {              //하여튼 저러한 필드 + 상위 클래스 필드를 포함한 소켓구현 객체 생성
55          // Nothing needed
56      }


289    void setServerSocket(ServerSocket soc) {
290        this.serverSocket = soc;         //휴~ 이제야 자신의 서버소켓에 세팅하네 -_- ㅎㄷㄷ
291    }


5.자~ 저 위에 2번에서 서버 소켓 생성을 하였으니.. 
 bind(new InetSocketAddress(bindAddr, port), backlog); 이놈을 추적해 봅니다. 좀 깁니다. 정신 단단히 붙잡고 gogo

358    public void More ...bind(SocketAddress endpoint, int backlog) throws IOException {
359        if (isClosed())
360            throw new SocketException("Socket is closed");
361        if (!oldImpl && isBound())
362            throw new SocketException("Already bound");
363        if (endpoint == null)
364            endpoint = new InetSocketAddress(0);
365        if (!(endpoint instanceof InetSocketAddress))
366            throw new IllegalArgumentException("Unsupported address type");
367        InetSocketAddress epoint = (InetSocketAddress) endpoint;
368        if (epoint.isUnresolved())
369            throw new SocketException("Unresolved address");
370        if (backlog < 1)
371          backlog = 50;

5.1자.. 위에까진 매개변수 유효성 처리였습니다. 아래의 시큐리티 매니저는 접속인증등 사용권한을 체크해주고 관리해줍니다.
중요한 메서드는 getImpl().bind() , getImpl().listen() 입니다.  독특한게.. 자신이 아까 생성한 구현체에 일을 떠맡기고
있습니다. (이게 인터페이스 클래스와 구현 클래스의 구분 목적입니다. = 추상화)

구현 객체의 bind() , listen() 을 추적하러 갑니다. 화이팅!! gogo 
참고로 구현객체 클래스는 4번에서 찾아봤지요..! 그때는 멤버 필드와 생성자만 봤었지만!

372        try {
373            SecurityManager security = System.getSecurityManager();
374            if (security != null)
375                security.checkListen(epoint.getPort());
376            getImpl().bind(epoint.getAddress(), epoint.getPort());
377            getImpl().listen(backlog);
378            bound = true;
379        } catch(SecurityException e) {
380            bound = false;
381            throw e;
382        } catch(IOException e) {
383            bound = false;
384            throw e;
385        }
386    }


6. 정신줄 놓지 않기!!! 
여기서 중요한게.. 소켓소켓임플 클래스의 상속 구조입니다. 확인! 
 class SocksSocketImpl extends PlainSocketImpl implements SocksConsts ... PlainSocketImpl을 상속 받습니다. 이름도 평범한 plain입니다.

자,.. 5번에서 추적하려던 소켓소켓임플 클래스의 bind()를 자세히 보면 매개변수가 2개 입니다.
매개변수가 2개인 bind()는 PlainSocketImpl()을 그대로 사용합니다. 그럼으로 아래의 bind()코드는 
PlainSocketImpl 클래스 파일에 정의된 메서드 입니다.

아래에서 NetHooks.beforeTcpBind(fd, address, lport); 는 파고들면 엄청 깊어짐으로 생략합니다.(sun.net 참고)
대신 애초 목적이였던 socketBind(address, lport) 를 열공 해야 합니다.


366    protected synchronized void bind(InetAddress address, int lport)
367        throws IOException
368    {
369       synchronized (fdLock) {  //멀티 스레딩을 대비해서 동기화 처리를 해주고 있습니다.
370            if (!closePending && (socket == null || !socket.isBound())) {
371                NetHooks.beforeTcpBind(fd, address, lport); //넷훅? 이름이 호기심 돋지만.. 유혹에 빠지면 안됨!
372            }
373        }
374        socketBind(address, lport); //너를 쪼개보리라!
375        if (socket != null)
376            socket.setBound();
377        if (serverSocket != null)
378            serverSocket.setBound();
379    }


7. 이런.. PlainSocketImpl 클래스에선 socketBind(매개변수 2개)를 추상 클래스로 선언했습니다. 하위클래스에
   구현이 되었겠군요?  다시 소켓소켓임플 클래스를 찾아봐야 겠습니다.
692    abstract void socketBind(InetAddress address, int port)
693        throws IOException;


****여기서 그만*****


'자바se api > net' 카테고리의 다른 글

네트워크 관련  (0) 2014.01.01
java.net.socket 파고들기1  (0) 2014.01.01
java.net 중 서버 소켓 -> IOCP -> NIO -> NODE JS + 팩토리 패턴  (0) 2014.01.01
by givingsheart 2014. 1. 1. 16:17
클라용 소켓 인터페이스부
서버용 소켓 인터페이스부

소켓 imple <-- 이것도 추상클래스로 빼놔서..

실제 추상화된 단계는
1.abstract class More ...AbstractPlainSocketImpl extends SocketImpl
2.class More ...PlainSocketImpl extends AbstractPlainSocketImpl
3.class More ...SocksSocketImpl extends PlainSocketImpl implements SocksConsts

하여튼.. 자신의 단계에서 가능한 메서드를 정의해두고 나머진 하위 클래스에게 맡겨버림..


1에서 볼만한건.. 클래스 멤버(static) 초기화 부분에서 먼짓을 하고 있는지!

79     static {
80         java.security.AccessController.doPrivileged(
81                   new sun.security.action.LoadLibraryAction("net"));
82     }

또한 create메서드에서 동기화 처리및 , 스트림 여부에 따라 udp 소켓 생성.. 리소스 매니저 사용..등

88     protected synchronized void More ...create(boolean stream) throws IOException {
89         fd = new FileDescriptor();
90         this.stream = stream;
91         if (!stream) {
92             ResourceManager.beforeUdpCreate();
93             try {
94                 socketCreate(false);
95             } catch (IOException ioe) {
96                 ResourceManager.afterUdpClose();
97                 fd = null;
98                 throw ioe;
99             }
100        } else {
101            socketCreate(true);
102        }
103        if (socket != null)
104            socket.setCreated();
105        if (serverSocket != null)
106            serverSocket.setCreated();
107    }

3에서 볼만한건..((SocketInputStream)in).read(data, received, len - received, remainingMillis(deadlineMillis));

117     private int More ...readSocksReply(InputStream in, byte[] data, long deadlineMillis) throws IOException {
118         int len = data.length;
119         int received = 0;
120         for (int attempts = 0; received < len && attempts < 3; attempts++) {
121             int count;
122             try {
123                 count = ((SocketInputStream)in).read(data, received, len - received, remainingMillis(deadlineMillis));
124             } catch (SocketTimeoutException e) {
125                 throw new SocketTimeoutException("Connect timed out");
126             }
127             if (count < 0)
128                 throw new SocketException("Malformed reply from SOCKS server");
129             received += count;
130         }
131         return received;
132     }

여튼 맞는지 모르겟지만,, 브릿지 패턴같음 


51 public
52 class More ...ServerSocket implements java.io.Closeable {
    

55 
56     private boolean created = false;
57     private boolean bound = false;
58     private boolean closed = false;
59     private Object closeLock = new Object();

    
63 
64     private SocketImpl impl;

   
68 
69     private boolean oldImpl = false;

    
75     More ...ServerSocket(SocketImpl impl) {
76         this.impl = impl;
77         impl.setServerSocket(this);
78     }

    

85 
86     public More ...ServerSocket() throws IOException {
87         setImpl();
88     }

    
//팩토리 클래스에서 실제 소켓 구현 클래스 얻고.. 추상 팩토리 패턴;;;
//시큐리티 매니저도.. 아.. 모르겠다..
SocketImpl
SocketImplFactory.createSocketImpl()
setSocketFactory(java.net.SocketImplFactory)
java.lang.SecurityManager.checkListen(int)
126
127    public More ...ServerSocket(int port) throws IOException {
128        this(port, 50, null);
129    }

    

180    public More ...ServerSocket(int port, int backlog) throws IOException {
181        this(port, backlog, null);
182    }


228
229    public More ...ServerSocket(int port, int backlog, InetAddress bindAddr) throws IOException {
230        setImpl();
231        if (port < 0 || port > 0xFFFF)
232            throw new IllegalArgumentException(
233                       "Port value out of range: " + port);
234        if (backlog < 1)
235          backlog = 50;
236        try {
237            bind(new InetSocketAddress(bindAddr, port), backlog);
238        } catch(SecurityException e) {
239            close();
240            throw e;
241        } catch(IOException e) {
242            close();
243            throw e;
244        }
245    }

    

//아래의 AccessController.doPrivileged .. 내가 awt 분석하면서 많이본 코드 조각.. 
//특별한 권한을 부여한다는 건데..  아래보면 reflect를 통해 소켓구현 클래스에..
//정의된 connect메서드를 얻는다.  하여간.. 이코드의 존재 의미를 명확히 모르겠다..

254
255    SocketImpl More ...getImpl() throws SocketException {
256        if (!created)
257            createImpl();
258        return impl;
259    }
260
261    private void More ...checkOldImpl() {
262        if (impl == null)
263            return;
264        // SocketImpl.connect() is a protected method, therefore we need to use
265        // getDeclaredMethod, therefore we need permission to access the member
266        try {
267            AccessController.doPrivileged(
268                new PrivilegedExceptionAction<Void>() {
269                    public Void More ...run() throws NoSuchMethodException {
270                        Class[] cl = new Class[2];
271                        cl[0] = SocketAddress.class;
272                        cl[1] = Integer.TYPE;
273                        impl.getClass().getDeclaredMethod("connect", cl);
274                        return null;
275                    }
276                });
277        } catch (java.security.PrivilegedActionException e) {
278            oldImpl = true;
279        }
280    }
281
282    private void More ...setImpl() {
283        if (factory != null) {
284            impl = factory.createSocketImpl();
285            checkOldImpl();
286        } else {
287            // No need to do a checkOldImpl() here, we know it's an up to date
288            // SocketImpl!
289            impl = new SocksSocketImpl();
290        }
291        if (impl != null)
292            impl.setServerSocket(this);
293    }

 
300
301    void More ...createImpl() throws SocketException {
302        if (impl == null)
303            setImpl();
304        try {
305            impl.create(true);
306            created = true;
307        } catch (IOException e) {
308            throw new SocketException(e.getMessage());
309        }
310    }

328
329    public void More ...bind(SocketAddress endpoint) throws IOException {
330        bind(endpoint, 50);
331    }

    
//유효한 연결인지 체크하고, 시큐리티 검사하고, 바인드 하고 , 바로 리슨을 해주는 걸 확인..

357
358    public void More ...bind(SocketAddress endpoint, int backlog) throws IOException {
359        if (isClosed())
360            throw new SocketException("Socket is closed");
361        if (!oldImpl && isBound())
362            throw new SocketException("Already bound");
363        if (endpoint == null)
364            endpoint = new InetSocketAddress(0);
365        if (!(endpoint instanceof InetSocketAddress))
366            throw new IllegalArgumentException("Unsupported address type");
367        InetSocketAddress epoint = (InetSocketAddress) endpoint;
368        if (epoint.isUnresolved())
369            throw new SocketException("Unresolved address");
370        if (backlog < 1)
371          backlog = 50;
372        try {
373            SecurityManager security = System.getSecurityManager();
374            if (security != null)
375                security.checkListen(epoint.getPort());
376            getImpl().bind(epoint.getAddress(), epoint.getPort());
377            getImpl().listen(backlog);
378            bound = true;
379        } catch(SecurityException e) {
380            bound = false;
381            throw e;
382        } catch(IOException e) {
383            bound = false;
384            throw e;
385        }
386    }

    
398    public InetAddress More ...getInetAddress() {
399        if (!isBound())
400            return null;
401        try {
402            return getImpl().getInetAddress();
403        } catch (SocketException e) {
404            // nothing
405            // If we're bound, the impl has been created
406            // so we shouldn't get here
407        }
408        return null;
409    }

    
421    public int More ...getLocalPort() {
422        if (!isBound())
423            return -1;
424        try {
425            return getImpl().getLocalPort();
426        } catch (SocketException e) {
427            // nothing
428            // If we're bound, the impl has been created
429            // so we shouldn't get here
430        }
431        return -1;
432    }

    
449
450    public SocketAddress More ...getLocalSocketAddress() {
451        if (!isBound())
452            return null;
453        return new InetSocketAddress(getInetAddress(), getLocalPort());
454    }

 
484    public Socket More ...accept() throws IOException {
485        if (isClosed())
486            throw new SocketException("Socket is closed");
487        if (!isBound())
488            throw new SocketException("Socket is not bound yet");
489        Socket s = new Socket((SocketImpl) null);
490        implAccept(s);
491        return s;
492    }

//시큐리티 매니저의 역할에 대해 생각해볼것! (즉 외부인 네트워크를 통한 스트림 연결에대해 인증및, 권한 설정등의 보안 작업)
509
510    protected final void More ...implAccept(Socket s) throws IOException {
511        SocketImpl si = null;
512        try {
513            if (s.impl == null)
514              s.setImpl();
515            else {
516                s.impl.reset();
517            }
518            si = s.impl;
519            s.impl = null;
520            si.address = new InetAddress();
521            si.fd = new FileDescriptor();
522            getImpl().accept(si);
523
524            SecurityManager security = System.getSecurityManager();
525            if (security != null) {
526                security.checkAccept(si.getInetAddress().getHostAddress(),
527                                     si.getPort());
528            }
529        } catch (IOException e) {
530            if (si != null)
531                si.reset();
532            s.impl = si;
533            throw e;
534        } catch (SecurityException e) {
535            if (si != null)
536                si.reset();
537            s.impl = si;
538            throw e;
539        }
540        s.impl = si;
541        s.postAccept();
542    }

556
557    public void More ...close() throws IOException {
558        synchronized(closeLock) {
559            if (isClosed())
560                return;
561            if (created)
562                impl.close();
563            closed = true;
564        }
565    }


582
583    public ServerSocketChannel More ...getChannel() {
584        return null;
585    }

592
593    public boolean More ...isBound() {
594        // Before 1.3 ServerSockets were always bound during creation
595        return bound || oldImpl;
596    }

    

603
604    public boolean More ...isClosed() {
605        synchronized(closeLock) {
606            return closed;
607        }
608    }


625
626    public synchronized void More ...setSoTimeout(int timeout) throws SocketException {
627        if (isClosed())
628            throw new SocketException("Socket is closed");
629        getImpl().setOption(SocketOptions.SO_TIMEOUT, new Integer(timeout));
630    }

    
639
640    public synchronized int More ...getSoTimeout() throws IOException {
641        if (isClosed())
642            throw new SocketException("Socket is closed");
643        Object o = getImpl().getOption(SocketOptions.SO_TIMEOUT);
644        /* extra type safety */
645        if (o instanceof Integer) {
646            return ((Integer) o).intValue();
647        } else {
648            return 0;
649        }
650    }


687
688    public void More ...setReuseAddress(boolean on) throws SocketException {
689        if (isClosed())
690            throw new SocketException("Socket is closed");
691        getImpl().setOption(SocketOptions.SO_REUSEADDR, Boolean.valueOf(on));
692    }

    
702
703    public boolean More ...getReuseAddress() throws SocketException {
704        if (isClosed())
705            throw new SocketException("Socket is closed");
706        return ((Boolean) (getImpl().getOption(SocketOptions.SO_REUSEADDR))).booleanValue();
707    }


714
715    public String More ...toString() {
716        if (!isBound())
717            return "ServerSocket[unbound]";
718        return "ServerSocket[addr=" + impl.getInetAddress() +
719                ",port=" + impl.getPort() +
720                ",localport=" + impl.getLocalPort()  + "]";
721    }
722
723    void More ...setBound() {
724        bound = true;
725    }
726
727    void More ...setCreated() {
728        created = true;
729    }

    
The factory for all server sockets.
733
734    private static SocketImplFactory factory = null;


760
761    public static synchronized void More ...setSocketFactory(SocketImplFactory fac) throws IOException {
762        if (factory != null) {
763            throw new SocketException("factory already defined");
764        }
765        SecurityManager security = System.getSecurityManager();
766        if (security != null) {
767            security.checkSetFactory();
768        }
769        factory = fac;
770    }


806
807     public synchronized void More ...setReceiveBufferSize (int size) throws SocketException {
808        if (!(size > 0)) {
809            throw new IllegalArgumentException("negative receive size");
810        }
811        if (isClosed())
812            throw new SocketException("Socket is closed");
813        getImpl().setOption(SocketOptions.SO_RCVBUF, new Integer(size));
814    }

828
829    public synchronized int More ...getReceiveBufferSize()
830    throws SocketException{
831        if (isClosed())
832            throw new SocketException("Socket is closed");
833        int result = 0;
834        Object o = getImpl().getOption(SocketOptions.SO_RCVBUF);
835        if (o instanceof Integer) {
836            result = ((Integer)o).intValue();
837        }
838        return result;
839    }


878
879    public void More ...setPerformancePreferences(int connectionTime,
880                                          int latency,
881                                          int bandwidth)
882    {
883        /* Not implemented yet */
884    }
885
886}


'자바se api > net' 카테고리의 다른 글

네트워크 관련  (0) 2014.01.01
java.net.socket 파고들기2  (0) 2014.01.01
java.net 중 서버 소켓 -> IOCP -> NIO -> NODE JS + 팩토리 패턴  (0) 2014.01.01
by givingsheart 2014. 1. 1. 16:16


java.net.serversocket 

이 클래스는 서버 소켓을 구현합니다. 서버 소켓은, 네트워크 경유로 요구가 보내져 오는 것을 기다립니다. 이것은, 그 요구에 근거해 몇개의 조작을 실행합니다. 그 후, 경우에 따라서는 요구 바탕으로 결과를 돌려줍니다.  

서버 소켓의 실제의 처리는,SocketImpl 클래스의 인스턴스에 의해 실행됩니다. 어플리케이션은, 소켓 구현을 작성하는 소켓 팩토리를 변경하는 것으로, 로컬 방화벽(fire wall)에 적절한 소켓을 작성하도록(듯이) 어플리케이션 자체를 구성할 수가 있습니다.

도입된 버젼:
JDK1. 0
관련 항목:
SocketImpl , setSocketFactory(java.net.SocketImplFactory) , ServerSocketChannel

=>서버 소켓의 accecpt() 메서드는 인터페이스 클래스(상위 클래스) 구현 클래스(하위클래스)
로 구성되었다(왜냐묜.. 소스코드 로직 유출 막을라고;; 사실 클라가 알 필요도 없고.. 추상화)

imple 클래스 선언부만 보면 아주 심플함.. 서버 소켓도 될수 있고, 일반 소켓도 될수
있고.. 게다가 인터페이스(메서드)의 경우.. 초 단순.. create , connect, accept , bind,
listen, getInputStream, getOutputStream, close .. 물론 다른 메서드도 있지만.. 초심플
아닌가??  


44 public abstract class More ...SocketImpl implements SocketOptions {
    
The actual Socket object.
47 
48     Socket socket = null;
49     ServerSocket serverSocket = null;

54     protected FileDescriptor fd;

59     protected InetAddress address;


64     protected int port;

69     protected int localport;


79     protected abstract void More ...create(boolean stream) throws IOException;

89     protected abstract void More ...connect(String host, int port) throws IOException;

99     protected abstract void More ...connect(InetAddress address, int port) throws IOException;

112    protected abstract void More ...connect(SocketAddress address, int timeout) throws IOException;

121    protected abstract void More ...bind(InetAddress host, int port) throws IOException;

132    protected abstract void More ...listen(int backlog) throws IOException;

141    protected abstract void More ...accept(SocketImpl s) throws IOException;

150    protected abstract InputStream More ...getInputStream() throws IOException;

159    protected abstract OutputStream More ...getOutputStream() throws IOException;

170    protected abstract int More ...available() throws IOException;

177    protected abstract void More ...close() throws IOException;

194    protected void More ...shutdownInput() throws IOException {
195      throw new IOException("Method not implemented!");
196    }

214    protected void More ...shutdownOutput() throws IOException {
215      throw new IOException("Method not implemented!");
216    }

224    protected FileDescriptor More ...getFileDescriptor() {
225        return fd;
226    }

234    protected InetAddress More ...getInetAddress() {
235        return address;
236    }

244    protected int More ...getPort() {
245        return port;
246    }

257    protected boolean More ...supportsUrgentData () {
258        return false; // must be overridden in sub-class
259    }

269    protected abstract void More ...sendUrgentData (int data) throws IOException;

277    protected int More ...getLocalPort() {
278        return localport;
279    }
280
281    void More ...setSocket(Socket soc) {
282        this.socket = soc;
283    }
284
285    Socket More ...getSocket() {
286        return socket;
287    }
288
289    void More ...setServerSocket(ServerSocket soc) {
290        this.serverSocket = soc;
291    }
292
293    ServerSocket More ...getServerSocket() {
294        return serverSocket;
295    }

302    public String More ...toString() {
303        return "Socket[addr=" + getInetAddress() +
304            ",port=" + getPort() + ",localport=" + getLocalPort()  + "]";
305    }
306
307    void More ...reset() throws IOException {
308        address = null;
309        port = 0;
310        localport = 0;
311    }

350
351    protected void More ...setPerformancePreferences(int connectionTime,
352                                          int latency,
353                                          int bandwidth)
354    {
355        /* Not implemented yet */
356    }
357}


***************************************************************

소켓의 인풋스트림에 뭔가 데이터가 들어왔을때.. 통지 해주는 객체와 내가 리스너(콜백메서드)
를 정의해서 붙여주는 처리는 아닌가? 
그냥 while()문에서 0.001초마다 메세지 들어와있나 확인해야 하나?

그리고 iocp개념, non blocking 통신은.. 아..................


iocp 관련 논의 (자바에선 어찌하는지 찾아봐야함)

http://www.gamecodi.com/board/zboard-id-GAMECODI_Talkdev-no-1607-z-14.htm

(추가)
다중 접속 처리를 위해 -> 소켓당 여러 프로세스 배정 -> 조금 더 가벼운 멀티 스레드 할당 ->
스레드 풀의 개념(스레드 생성,소멸 시간 절약해 재사용) -> 메모리 문제, 성능 문제등이 발생을
한다. 동기화 IO의 한계가 존재함으로.. 비동기 IO인 NIO패키지로 해결을 하며, 고속의 성능이
필요할 경운.. 자바가 아닌 C++ 등으로 구현하는 것이 현명할 것이다.

(추가)
NODE JS 를 공부하게 되었다. 싱글 스레드 서버로서 파일등 I/O의 경우는 비동기로 처리한다.(이벤트
큐와 리스너와 콜백)

NODE의 경우 싱글 스레드로서, 동기화의 문제 , 멀티스레드 문제를 극복하게 하지만, 싱글 스레드 임으로
서버 컴퓨터(멀티코어)의 능력을 제대로 쓰기 위해서는 클러스터 모듈을 사용해서 분산 처리해야 한다.
또한 서버단에서 CPU 연산이 많은 작업을 하게 되면, 비동기적 프로그래밍을 제대로 구현하지 못할 경우..
 병목 현상이 발생한다. 서버는 참으로 어렵고 크리티컬한 분야이다.


게임서버 관련 쟁점
http://cafe.naver.com/jzsdn/23094?social=1

(추가)
게임 서버는.. 다중 접속, 빠른 처리, 지역 분할과 동기화란.. 너무나 많은 이슈가 걸려있다.

서버 동작 방식 결정하게끔 생성하는 팩토리 메서드 패턴?
http://cafe.naver.com/gogoxna/934

(추가)
일단 팩토리 패턴이란.. 객체 생성 과정을 추상화 하기 위한 개념이다. GETINSTANCE ("객체 이름")
서로 다른 모듈(또는 시스템)간에는 서로를 구체적으로 몰라야 유연성(루즈커플링)이 높아진다.
유연성이 높아야, 변경에 취약하지가 않게 된다.


'자바se api > net' 카테고리의 다른 글

네트워크 관련  (0) 2014.01.01
java.net.socket 파고들기2  (0) 2014.01.01
java.net.socket 파고들기1  (0) 2014.01.01
by givingsheart 2014. 1. 1. 16:14
| 1 |