Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A POSIX socket wrapper written in swift.

License

NotificationsYou must be signed in to change notification settings

BiAtoms/Socket.swift

Repository files navigation

Platform LinuxPlatform iOS macOS tvOSCocoapods CompatibleCarthage CompatibleLicenseBuild Status - Master

Socket.swift

A POSIX socket wrapper written in swift.

Features

  • TLS/SSL support
  • Linux, iOS, macOS and tvOS support
  • Clean and understanable code

If you consider something needs to be implemented, justopen an issue or make a PR

Example

letserver=trySocket(.inet, type:.stream, protocol:.tcp) // create server sockettry server.set(option:.reuseAddress,true) // set SO_REUSEADDR to 1try server.bind(port:8090, address:nil) // bind 'localhost:8090' address to the sockettry server.listen() // allow incoming connectionsletclient=trySocket(.inet, type:.stream, protocol:.tcp) // create client sockettry client.connect(port:8090) // connect to localhost:8090letclientAtServerside=try server.accept() // accept client connectionlethelloBytes=([UInt8])("Hello World".utf8)try clientAtServerside.write(helloBytes) // sending bytes to the clientclientAtServerside.close()varbuffer=[UInt8](repeating:0, count: helloBytes.count) // allocate bufferletnumberOfReadBytes=try client.read(&buffer, size: helloBytes.count)print(numberOfReadBytes== helloBytes.count) // trueprint(buffer== helloBytes) // trueclient.close()server.close()

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate Socket.swift into your Xcode project using CocoaPods, specify it in yourPodfile:

source'https://github.com/CocoaPods/Specs.git'target'<Your Target Name>'dopod'Socket.swift','~> 2.4.0'end

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage withHomebrew using the following command:

$ brew update$ brew install carthage

To integrate Socket.swift into your Xcode project using Carthage, specify it in yourCartfile:

github "BiAtoms/Socket.swift" ~> 2.4.0

Runcarthage update to build the framework and drag the builtSocketSwift.framework into your Xcode project.

Swift Package Manager

TheSwift Package Manager is a tool for automating the distribution of Swift code and is integrated into theswift compiler. It is in early development, but Socket.swift does support its use on supported platforms.

Once you have your Swift package set up, adding Socket.swift as a dependency is as easy as adding it to thedependencies value of yourPackage.swift.

dependencies:[.package(url:"https://github.com/BiAtoms/Socket.swift.git", from:"2.4.0")]

Manually

Just drag and drop the files in theSources folder.

Authors

See also the list ofcontributors who participated in this project.

License

This project is licensed under the MIT License - see theLICENSE file for details


[8]ページ先頭

©2009-2025 Movatter.jp