{"id":3097,"url":"https://github.com/swiftsocket/SwiftSocket","last_synced_at":"2025-08-06T14:31:19.314Z","repository":{"id":19917117,"uuid":"23182992","full_name":"swiftsocket/SwiftSocket","owner":"swiftsocket","description":"The easy way to use sockets on Apple platforms","archived":false,"fork":false,"pushed_at":"2023-12-12T12:10:31.000Z","size":329,"stargazers_count":1682,"open_issues_count":115,"forks_count":401,"subscribers_count":52,"default_branch":"master","last_synced_at":"2024-10-26T00:58:42.889Z","etag":null,"topics":["socket","swift","swiftsocket"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/swiftsocket.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-08-21T10:20:39.000Z","updated_at":"2024-10-15T09:38:31.000Z","dependencies_parsed_at":"2024-06-18T12:07:32.527Z","dependency_job_id":"40b9fc7a-6a2c-4bf5-ab5d-b5c54c40cbfc","html_url":"https://github.com/swiftsocket/SwiftSocket","commit_stats":{"total_commits":101,"total_committers":33,"mean_commits":"3.0606060606060606","dds":0.7128712871287128,"last_synced_commit":"97b7599da90f9c07ecf65551718706dc30e6838e"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiftsocket%2FSwiftSocket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiftsocket%2FSwiftSocket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiftsocket%2FSwiftSocket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiftsocket%2FSwiftSocket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/swiftsocket","download_url":"https://codeload.github.com/swiftsocket/SwiftSocket/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227627374,"owners_count":17795949,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["socket","swift","swiftsocket"],"created_at":"2024-01-05T20:16:31.293Z","updated_at":"2024-12-09T14:31:16.244Z","avatar_url":"https://github.com/swiftsocket.png","language":"Swift","readme":"# SwiftSocket\n[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/SwiftSocket.svg)](https://cocoapods.org/pods/SwiftSocket)\n[![CocoaPods Platforms](https://img.shields.io/cocoapods/p/SwiftSocket.svg)](https://img.shields.io/cocoapods/p/SwiftSocket.svg)\n[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n\nSwiftSocket library provides as easy to use interface for socket based connections on server or client side.\nSupports both TCP and UDP sockets.\n\n\n# Installation\n## Cocoapods\nAdd this to your `Podfile`:\n```ruby\npod 'SwiftSocket'\n```\nAnd run then `pod install`\n\n## Carthage\n```ruby\ngithub \"swiftsocket/SwiftSocket\"\n```\n\n# Code examples\n\n## Create client socket\n``` swift\n// Create a socket connect to www.apple.com and port at 80\nlet client = TCPClient(address: \"www.apple.com\", port: 80)\n```\n## Connect with timeout\nYou can also set timeout to `-1` or leave parameters empty (`client.connect()`) to turn off connection timeout.\n``` swift\n switch client.connect(timeout: 10) {\n   case .success:\n     // Connection successful 🎉\n   case .failure(let error):\n     // 💩\n }\n```\n\n## Send data\n``` swift\nlet data: Data = // ... Bytes you want to send\nlet result = client.send(data: data)\n```\n\n## Read data\n``` swift\nvar data = client.read(1024*10) //return optional [Int8]\n```\n\n## Close socket\n``` swift\nclient.close()\n```\n\n## Client socket example\n``` swift\nlet client = TCPClient(address: \"www.apple.com\", port: 80)\nswitch client.connect(timeout: 1) {\n  case .success:\n    switch client.send(string: \"GET / HTTP/1.0\\n\\n\" ) {\n      case .success:\n        guard let data = client.read(1024*10) else { return }\n\n        if let response = String(bytes: data, encoding: .utf8) {\n          print(response)\n        }\n      case .failure(let error):\n        print(error)\n    }\n  case .failure(let error):\n    print(error)\n}\n\n```\n\n## Server socket example (echo server)\n``` swift\nfunc echoService(client: TCPClient) {\n    print(\"Newclient from:\\(client.address)[\\(client.port)]\")\n    var d = client.read(1024*10)\n    client.send(data: d!)\n    client.close()\n}\n\nfunc testServer() {\n    let server = TCPServer(address: \"127.0.0.1\", port: 8080)\n    switch server.listen() {\n      case .success:\n        while true {\n            if var client = server.accept() {\n                echoService(client: client)\n            } else {\n                print(\"accept error\")\n            }\n        }\n      case .failure(let error):\n        print(error)\n    }\n}\n```\n","funding_links":[],"categories":["WebSocket","Libs","Swift","Network [🔝](#readme)","Servers and Sockets"],"sub_categories":["Web View","Network","Other free courses"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswiftsocket%2FSwiftSocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswiftsocket%2FSwiftSocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswiftsocket%2FSwiftSocket/lists"}