1234567891011121314151617181920212223242526272829303132333435363738394041 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace TcpEventBus
- {
- public interface ISocket
- {
- public int ReceiveTimeout { get; }
- public Action OnConnected { get; set; }
- public Action<ArraySegment<byte>> OnData { get; set; }
- public Action OnDisconnected { get; set; }
- public bool IsConnect { get; }
- public void Disconnect();
- public bool IsService { get; }
- public void Start();
- /// <summary>
- /// 发生数据
- /// </summary>
- /// <param name="data"></param>
- public void Send(byte[] data);
- public static class SocketTool
- {
- public static ISocket CreateService(int port, int timeout = 1000)
- {
- return new Server("0.0.0.0", port)
- {
- };
- }
- public static ISocket CreateClient(string ip, int port, int timeout = 1000)
- {
- return new Client(ip, port)
- {
- };
- }
- }
- }
- }
|