본문 바로가기
프로젝트

놀이동산 프로젝트 - 기능 및 개념 공부

by 정구지개발자 2025. 3. 11.
728x90

<Socket>

 

 

Socket(String host, int port)

Creates a stream socket and connects it to the specified port number on the named host.

 

getInputStream()
Returns an input stream for this socket.

 

InputStream은 데이터를 byte 단위로 읽어들이는 통로이며 (읽어들인 데이터를 byte로 돌려줌)

InputStream이 갖춰야 할 덕목으로는

  • 데이터 읽기
  • 특정 시점으로 되돌아가기
  • 얼마나 데이터가 남았는지 보여주기
  • 통로 끊기

Stream

개별 바이트나 문자열인 데이터의 원천
파일을 읽거나 쓸 때, 네트워크 소켓을 거쳐 통신할 때 쓰이는 추상적인 개념

데이터가 전송되는 통로

데이터가 네트워크를 거치건, 파일에서 넘어오건, 키보드로부터 오건, 데이터가 오고가는 통로가 스트림

 

getOutputStream()

Returns an output stream for this socket.

 

OuputStream은 쓸 수 있어야 한다

파일로 보내건, 메모리로 보내건, 네트워크로 보내건 통로로 데이터를 내부내는 기능이 필요하다!

 

OutputStream이 갖춰야 할 덕목으로는

  • 데이터 쓰기
  • 버퍼 비우기
  • 통로 끊기

 

 

<serverSocket>

 

This class implements server sockets. A server socket waits for requests to come in over the network. It performs some operation based on that request, and then possibly returns a result to the requester.

 

ServerSocket(int port)

Creates a server socket, bound to the specified port.
 

 

public Socket accept()
              throws IOException
Listens for a connection to be made to this socket and accepts it. The method blocks until a connection is made.

A new Socket s is created and, if there is a security manager, the security manager's checkAccept method is called with s.getInetAddress().getHostAddress() and s.getPort() as its arguments to ensure the operation is allowed. This could result in a SecurityException.

Returns:the new Socket

 

ex) serverSocket = new ServerSocket(9999);

Socket socket  = serverSocket.accept();

 

 

728x90

'프로젝트' 카테고리의 다른 글

이미지 상대경로  (0) 2025.03.14
JFrame  (0) 2025.03.12
query 문 및 이미지 url  (0) 2025.03.12
놀이동산 프로젝트 - 기능 및 개념 공부  (0) 2025.03.11
github issues참고사이트  (0) 2025.03.11

댓글