All Projects → swiftsocket → Swiftsocket

swiftsocket / Swiftsocket

Licence: bsd-3-clause
The easy way to use sockets on Apple platforms

Programming Languages

swift
15916 projects
c
50402 projects - #5 most used programming language
ruby
36898 projects - #4 most used programming language
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to Swiftsocket

Fccss
Computer Science SCHOOL resources
Stars: ✭ 84 (-94.39%)
Mutual labels:  socket
Phpforker
A simple Multi-Process programming skeleton written in PHP and learned much from Workerman, which remove the part of Network Event Library. It aims at helping us study PHP Multi-Process programming & find out how Workerman core works.
Stars: ✭ 96 (-93.59%)
Mutual labels:  socket
Python Examples
Python examples from my answers on Stackoverflow and other short scripts.
Stars: ✭ 101 (-93.25%)
Mutual labels:  socket
Advanced Php
最近打算写一些php一些偏微妙的教程,比如关于多进程、socket等相关,都是自己的一些感悟心得
Stars: ✭ 1,271 (-15.1%)
Mutual labels:  socket
Chat.io
A Real Time Chat Application built using Node.js, Express, Mongoose, Socket.io, Passport, & Redis.
Stars: ✭ 1,325 (-11.49%)
Mutual labels:  socket
Kitura Net
Kitura networking
Stars: ✭ 98 (-93.45%)
Mutual labels:  socket
Railschat
Real-time Rails-based Webchat for Instant Messaging (实时Web聊天室)
Stars: ✭ 81 (-94.59%)
Mutual labels:  socket
Deta cache
缓存cache服务器
Stars: ✭ 106 (-92.92%)
Mutual labels:  socket
T Io
解决其它网络框架没有解决的用户痛点,让天下没有难开发的网络程序
Stars: ✭ 1,331 (-11.09%)
Mutual labels:  socket
Jupiter
Jupiter是一款性能非常不错的, 轻量级的分布式服务框架
Stars: ✭ 1,372 (-8.35%)
Mutual labels:  socket
Workerman
An asynchronous event driven PHP socket framework. Supports HTTP, Websocket, SSL and other custom protocols. PHP>=5.3.
Stars: ✭ 9,617 (+542.42%)
Mutual labels:  socket
Springboot im
使用springboot + nettysocketio开发的一个简易卡牌游戏。主要想了解游戏服务端开发流程,基本逻辑等相关知识和长连接。
Stars: ✭ 94 (-93.72%)
Mutual labels:  socket
Lamp
A simple controller of craft lamp for Android.
Stars: ✭ 99 (-93.39%)
Mutual labels:  socket
Tcpraw
Sending packets through TCP
Stars: ✭ 86 (-94.26%)
Mutual labels:  socket
Chatroom
vue2聊天室,图灵机器人,node爬虫
Stars: ✭ 103 (-93.12%)
Mutual labels:  socket
Jocket
Low-latency java socket implementation (using shared memory)
Stars: ✭ 83 (-94.46%)
Mutual labels:  socket
Smux
smux is a socket multiplexer written in Golang. It provides fast communication by efficiently a single connection.
Stars: ✭ 97 (-93.52%)
Mutual labels:  socket
Rltm.js
Easily swap realtime providers with a single code base
Stars: ✭ 106 (-92.92%)
Mutual labels:  socket
Socket.io Redux
Redux middleware to emit action via socket.io
Stars: ✭ 103 (-93.12%)
Mutual labels:  socket
Kcp
⚡ KCP - A Fast and Reliable ARQ Protocol
Stars: ✭ 10,473 (+599.6%)
Mutual labels:  socket

SwiftSocket

CocoaPods Compatible CocoaPods Platforms Carthage Compatible

SwiftSocket library provides as easy to use interface for socket based connections on server or client side. Supports both TCP and UDP sockets.

Installation

Cocoapods

Add this to your Podfile:

pod 'SwiftSocket'

And run then pod install

Carthage

github "swiftsocket/SwiftSocket"

Code examples

Create client socket

// Create a socket connect to www.apple.com and port at 80
let client = TCPClient(address: "www.apple.com", port: 80)

Connect with timeout

You can also set timeout to -1 or leave parameters empty (client.connect()) to turn off connection timeout.

 switch client.connect(timeout: 10) {
   case .success:
     // Connection successful 🎉
   case .failure(let error):
     // 💩
 }

Send data

let data: Data = // ... Bytes you want to send
let result = client.send(data: data)

Read data

var data = client.read(1024*10) //return optional [Int8]

Close socket

client.close()

Client socket example

let client = TCPClient(address: "www.apple.com", port: 80)
switch client.connect(timeout: 1) {
  case .success:
    switch client.send(string: "GET / HTTP/1.0\n\n" ) {
      case .success:
        guard let data = client.read(1024*10) else { return }

        if let response = String(bytes: data, encoding: .utf8) {
          print(response)
        }
      case .failure(let error):
        print(error)
    }
  case .failure(let error):
    print(error)
}

Server socket example (echo server)

func echoService(client: TCPClient) {
    print("Newclient from:\(client.address)[\(client.port)]")
    var d = client.read(1024*10)
    client.send(data: d!)
    client.close()
}

func testServer() {
    let server = TCPServer(address: "127.0.0.1", port: 8080)
    switch server.listen() {
      case .success:
        while true {
            if var client = server.accept() {
                echoService(client: client)
            } else {
                print("accept error")
            }
        }
      case .failure(let error):
        print(error)
    }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].