Server.swift 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Server.swift
  4. // Starscream
  5. //
  6. // Created by Dalton Cherry on 4/2/19.
  7. // Copyright © 2019 Vluxe. All rights reserved.
  8. //
  9. // Licensed under the Apache License, Version 2.0 (the "License");
  10. // you may not use this file except in compliance with the License.
  11. // You may obtain a copy of the License at
  12. //
  13. // http://www.apache.org/licenses/LICENSE-2.0
  14. //
  15. // Unless required by applicable law or agreed to in writing, software
  16. // distributed under the License is distributed on an "AS IS" BASIS,
  17. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. // See the License for the specific language governing permissions and
  19. // limitations under the License.
  20. //
  21. //////////////////////////////////////////////////////////////////////////////////////////////////
  22. import Foundation
  23. public enum ConnectionEvent {
  24. case connected([String: String])
  25. case disconnected(String, UInt16)
  26. case text(String)
  27. case binary(Data)
  28. case pong(Data?)
  29. case ping(Data?)
  30. case error(Error)
  31. }
  32. public protocol Connection {
  33. func write(data: Data, opcode: FrameOpCode)
  34. }
  35. public protocol ConnectionDelegate: AnyObject {
  36. func didReceive(event: ServerEvent)
  37. }
  38. public enum ServerEvent {
  39. case connected(Connection, [String: String])
  40. case disconnected(Connection, String, UInt16)
  41. case text(Connection, String)
  42. case binary(Connection, Data)
  43. case pong(Connection, Data?)
  44. case ping(Connection, Data?)
  45. }
  46. public protocol Server {
  47. func start(address: String, port: UInt16) -> Error?
  48. }