Python 2.7은 지원이 종료되었으며 2026년 1월 31일에 지원 중단됩니다. 지원 중단 후에는 조직에서 이전에 조직 정책을 사용하여 레거시 런타임의 배포를 다시 사용 설정한 경우에도 Python 2.7 애플리케이션을 배포할 수 없습니다. 기존 Python 2.7 애플리케이션은 지원 중단 날짜 이후에도 계속 실행되고 트래픽을 수신합니다. 지원되는 최신 Python 버전으로 마이그레이션하는 것이 좋습니다.
소켓의 트래픽 요금은 발신 대역폭으로 청구됩니다.
비동기 IO(예: Python의 Twisted)는 지원되지 않습니다.
App Engine은 표준 Python 소켓 모듈 API를 아웃바운드 소켓용으로만 지원합니다. 간단히 다음 문을 사용하여 표준 소켓 라이브러리를 가져올 수 있습니다.
importsocket
poplib 또는 nntplib와 같이 socket을 가져오고, 아래에 설명된 제한 및 제약사항을 위반하지 않는 라이브러리는 수정 없이 작동합니다.
Python 2 런타임은 소켓을 지원하지만 소켓을 사용할 때 알아야 할 몇 가지 제한 사항과 동작이 있습니다.
소켓 설명어를 피클하고 App Engine 인스턴스 간에 전달할 수 있습니다(예: 작업 페이로드의 일부). 이 경우에는 프런트엔드 인스턴스에서 소켓을 연 후 백엔드 인스턴스에 소켓을 전달하여 사용할 수 있습니다.
1.8.1 이전의 SDK 버전에서는 소켓에 대해 get/set 옵션을 호출할 수 없었습니다. 호출하면 "구현되지 않음" 예외가 발생했습니다. 하지만 이제 Sockets API는 이를 허용합니다.
지원되는 옵션의 경우, getsockopt를 호출하면 모의 값이 반환되고 setsockopt를 호출하면 자동으로 무시됩니다. 지원되지 않는 옵션에 대해서는 오류가 계속 발생합니다.
지원되는 옵션은 다음과 같습니다.
SO_KEEPALIVE
SO_DEBUG
TCP_NODELAY
SO_LINGER
SO_OOBINLINE
SO_SNDBUF
SO_RCVBUF
SO_REUSEADDR
제한 및 제약사항
App Engine의 소켓 지원에는 다음과 같은 제한사항이 있습니다.
리슨 소켓을 만들 수 없으며 아웃바운드 소켓만 만들 수 있습니다.
FTP는 지원되지 않습니다.
기본적으로 httplib는 urlfetch api를 사용하도록 구성됩니다. socket을 사용하여 urlfetch 제한을 우회해야 하는 경우, 이 기본값을 변경하여 httplib가 대신 소켓을 사용하도록 설정하면 됩니다. 자세한 내용은 httplib에서 소켓 사용을 참조하세요.
TCP 또는 UDP만 사용할 수 있습니다. 임의 프로토콜은 허용되지 않습니다.
특정 IP 주소 또는 포트로 바인딩할 수 없습니다.
포트 25(SMTP)가 차단됩니다. 제출 포트 587에서 인증된 SMTP를 계속 사용할 수 있습니다.
비공개, 브로드캐스트, 멀티캐스트, Google IP 범위는 아래 나열된 항목을 제외하고 차단됩니다.
Google Public DNS: 8.8.8.8, 8.8.4.4, 2001:4860:4860::8888, 2001:4860:4860::8844 포트 53
Gmail SMTPS: smtp.gmail.com 포트 465 및 587
Gmail POP3S: pop.gmail.com 포트 995
Gmail IMAPS: imap.gmail.com 포트 993
소켓 설명자는 자신을 만든 App Engine 앱에 연결되며 전송될 수 없습니다(다른 앱에서 사용 불가).
비활성 상태가 10분간 지속되는 소켓은 회수할 수 있습니다. 모든 소켓 작업에서 소켓이 10분 더 활성 상태로 유지됩니다.
현재 socket.gethostbyaddr()는 Python에 구현되어 있지 않습니다.
계속 Python SMTP 표준 라이브러리(smtplib)를 사용하여 연결을 생성할 수 있습니다.
# Open a connection to my mail servers=smtplib.SMTP('smtp.mailhostingcompany.net',587)
개발 서버와 소켓 사용
특수 명령줄 매개변수를 사용하지 않고 개발 서버에서 소켓을 사용하여 코드를 실행하고 테스트할 수 있습니다.
OpenSSL에서 소켓 사용
App Engine은 Python 2.7 런타임용 기본 Python OpenSSL을 지원합니다.
OpenSSL 지원에 설명된 대로 ssl 라이브러리를 로드하도록 app.yaml 파일을 구성해야 합니다.
URL 가져오기를 사용 중지하여 모든 아웃바운드 요청 처리
httplib를 가져오면 기본적으로 urlfetch api가 사용됩니다. httplib가 소켓을 사용하도록 변경하려면 app.yaml 파일에 다음 환경 변수를 추가합니다.
env_variables:GAE_USE_SOCKETS_HTTPLIB:'anyvalue'
anyvalue를 빈 문자열을 포함하여 모든 값으로 바꿀 수 있습니다.
소켓을 사용하는 App Engine 샘플
소켓을 사용하는 샘플은 Google Cloud Platform GitHub의 소켓 데모 앱을 참조하세요.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[[["\u003cp\u003eThis Sockets API is only functional within the Python 2 runtime, and it's recommended to use an alternative solution before migrating to the Python 3 runtime.\u003c/p\u003e\n"],["\u003cp\u003eApp Engine supports the standard Python socket module API, but only for outbound sockets, and libraries like \u003ccode\u003epoplib\u003c/code\u003e or \u003ccode\u003enntplib\u003c/code\u003e can work if they adhere to specified limitations.\u003c/p\u003e\n"],["\u003cp\u003eSockets have specific restrictions in App Engine, including the inability to create listen sockets, blocked protocols such as FTP, and the blocking of specific IP ranges.\u003c/p\u003e\n"],["\u003cp\u003eSocket descriptors can be passed between App Engine instances, for example, from a frontend to a backend instance.\u003c/p\u003e\n"],["\u003cp\u003eBy default, \u003ccode\u003ehttplib\u003c/code\u003e uses the URL fetch API, but you can configure it to use sockets instead by setting the \u003ccode\u003eGAE_USE_SOCKETS_HTTPLIB\u003c/code\u003e environment variable in your \u003ccode\u003eapp.yaml\u003c/code\u003e file.\u003c/p\u003e\n"]]],[],null,["# Sockets API for legacy bundled services\n\n| **Caution:** **This solution is no longer recommended:** Apps that use this API can only run in the Python 2 runtime and will need to upgrade to a [recommended solution](/appengine/migration-center/standard/services/migrating-services) before migrating to the Python 3 runtime.\n\nTraffic from sockets is billed as [outgoing bandwidth](/appengine/docs/pricing#Billable_Resource_Unit_Costs). Async IO (such as [Twisted](https://docs.twisted.org/) in Python) is not supported. App Engine supports the standard Python socket module API for outbound sockets only. You simply import the standard socket library using the following statement:\n\n\u003cbr /\u003e\n\n import socket\n\nLibraries that import `socket`, such as\n`poplib` or `nntplib`, and that don't violate the\n[limitations and restrictions](#limitations-and-restrictions) listed\nbelow, should work without modification.\n\nAlthough the Python 2 runtime supports sockets, there are certain\nlimitations and behaviors you need to be aware of when using sockets.\n\nYou can pickle a socket descriptor and pass it between App Engine\ninstances, such as part of a Task payload. In this scenario, you can open a\nsocket on a frontend instance, and then pass it to a backend instance and use it\nthere.\n\nIn SDK versions prior to 1.8.1, you could\nnot call get/set options against sockets. (Doing so raised \"Not Implemented\"\nexceptions.) However, the Sockets API now allows this.\n\nFor supported options,\ncalls to `getsockopt` will return a mock value and\ncalls to `setsockopt` will be silently ignored. Errors will continue to be\nraised for unsupported options.\n\n\nThe supported options are:\n\n- `SO_KEEPALIVE`\n- `SO_DEBUG`\n- `TCP_NODELAY`\n- `SO_LINGER`\n- `SO_OOBINLINE`\n- `SO_SNDBUF`\n- `SO_RCVBUF`\n- `SO_REUSEADDR`\n\nLimitations and restrictions\n----------------------------\n\nSocket support in App Engine has the following limitations:\n\n- You cannot create a listen socket; you can only create outbound sockets.\n- FTP is not supported.\n- By default, `httplib` is configured to use the [urlfetch api](/appengine/docs/legacy/standard/python/issue-requests); if you need to use `socket` to get around urlfetch limits, you can do so by changing this default so `httplib` uses sockets instead. For more information, see [Making `httplib` use sockets](#making_httplib_use_sockets).\n- You can only use TCP or UDP; arbitrary protocols are not allowed.\n- You cannot bind to specific IP addresses or ports.\n- Port 25 (SMTP) is blocked; you can still use authenticated SMTP on the submission port 587.\n- Private, broadcast, multicast, and Google IP ranges are blocked, except\n those listed below:\n\n - Google Public DNS: `8.8.8.8`, `8.8.4.4`, `2001:4860:4860::8888`, `2001:4860:4860::8844` port 53\n - Gmail SMTPS: `smtp.gmail.com` port 465 and 587\n - Gmail POP3S: `pop.gmail.com` port 995\n - Gmail IMAPS: `imap.gmail.com` port 993\n\n | **Note:** Google Compute Engine IP addresses are not considered to be in Google IP ranges. You can use sockets to connect App Engine apps to Compute Engine instances.\n- Socket descriptors are associated with the App Engine app that\n created them and are non-transferable (cannot be used by other apps).\n\n- Sockets may be reclaimed after 10 minutes of inactivity; any socket operation\n keeps the socket alive for a further 10 minutes.\n\n- Currently, `socket.gethostbyaddr()` is not implemented in Python.\n You can still use the Python SMTP standard library\n (`smtplib`) to open a connection:\n\n # Open a connection to my mail server\n s = smtplib.SMTP('smtp.mailhostingcompany.net', 587)\n\nUsing sockets with the development server\n-----------------------------------------\n\nYou can run and test code using sockets on the development server, without using\nany special command line parameters.\n\nUsing sockets with OpenSSL\n--------------------------\n\nApp Engine supports native Python OpenSSL for the Python 2.7 runtime.\nYou must configure your `app.yaml` file to load the ssl library, as described in\n[OpenSSL Support](/appengine/docs/legacy/standard/python/sockets/ssl_support).\n\nDisabling URL Fetch from handling all outbound requests\n-------------------------------------------------------\n\nIf you import `httplib`, by default it will use the\n[urlfetch api](/appengine/docs/legacy/standard/python/issue-requests). To change this\nso that `httplib` uses sockets instead, add the following environment variable\nto your `app.yaml` file: \n\n env_variables:\n GAE_USE_SOCKETS_HTTPLIB : 'anyvalue'\n\nYou can replace `anyvalue` with any value including an empty string.\n\n\nApp Engine sample using sockets\n-------------------------------\n\nFor a sample using sockets, see the [socket demo\napp](https://github.com/GoogleCloudPlatform/appengine-sockets-python-java-go)\nin the Google Cloud Platform GitHub."]]