/// <summary> /// /// </summary> /// <param name="context">The context of the socket</param> /// <param name="socket">Socket to monitor</param> /// <param name="address">Monitoring address to use</param> /// <param name="monitoringEventsHandler">The events handler interface</param> public MonitorPoll(Context context, BaseSocket socket, string address, IMonitoringEventsHandler monitoringEventsHandler) { Socket = socket; MonitorAddress = address; m_monitoringEventsHandler = monitoringEventsHandler; Context = context; Timeout = TimeSpan.FromSeconds(1); }
void ISocketEventListener.OnWrite(BaseSocket sock, byte[] buf, int offset, int length) { int tim = (int)m_listener[Options.KEEP_ALIVE]; if (tim > 0) { m_timer.Change(tim, tim); } m_listener.BytesWritten(buf, offset, length); }
void ISocketEventListener.OnConnect(BaseSocket sock) { #if !NO_SSL if ((bool)m_listener[Options.SSL]) { AsyncSocket s = sock as AsyncSocket; m_listener[Options.REMOTE_CERTIFICATE] = s.RemoteCertificate; } #endif m_listener.Connected(); }
bool ISocketEventListener.OnAccept(BaseSocket newsocket) { m_sock = newsocket; InitializeStream(); m_listener.Accepted(); // Don't accept any more connections until this one closes // yes, it will look like we're still listening until the old sock is free'd by GC. // don't want OnClose() to fire, though, so we can't close the previous sock. return(false); }
static void Main(string[] args) { Console.WriteLine("Enter Id : "); Id = Console.ReadLine(); Console.WriteLine("Enter Match Id : "); matchId = Console.ReadLine(); tcpSocket = new ConnectSocket(512, "127.0.0.1", 1618); tcpSocket.SocketActionEventHandler += TcpSocket_OnSocketAction; Console.ReadLine(); }
/// <summary> /// Listens for an inbound connection. /// </summary> public override void Accept() { AsyncSocket s = new AsyncSocket(null, this, (bool)m_listener[Options.SSL], false); s.LocalCertificate = m_listener[Options.LOCAL_CERTIFICATE] as System.Security.Cryptography.X509Certificates.X509Certificate2; m_sock = s; m_sock.Accept(new Address((int)m_listener[Options.PORT])); m_sock.RequestAccept(); }
public ChatNetworkService(BaseSocket socket, ConversationInfo info) : base(info) // string username { this.socket = socket; socket.OnMessageRecieved += OnMessageRecievedHandler; socket.OnSocketDisconnect += OnDisconnectHandler; socket.OnMessageParseException += OnMessageParseExceptionHandler; //socket.OnSocketDisconnect += () => //{ // OnServiceDisconnect?.Invoke(); //}; }
private void OnPartPlaced(BasePart part, BaseSocket socket) { if (part.GetComponent <AddonRemoveGrass>() == null) { return; } if (RemoveGrass) { StartCoroutine(RemoveGrassToPosition(part.transform.position, RemoveGrassRadius)); } }
public Boolean init() { IFacade = new IFacade(); baseSocket = new BaseSocket(); baseSocket.Socket(ProfileView.profile.serverIP, Int32.Parse(ProfileView.profile.serverPort)); baseSocket.onRecive += onRecive; baseSocket.onConnect += onConnect; baseSocket.onDisconect += onDisconect; baseSocket.onSent += onSent; baseSocket.connect(); return(true); }
public BaseSocket UpdateWirelessSocket(string name, BaseSocket wirelessSocket) { if (wirelessSocket.Name != name) { throw new ArgumentException("name does not name of wireless socket"); } var socket = _wirelessSockets.First(n => n.Name == name); socket = wirelessSocket; return(socket); }
void EndAccept() { Socket serverClientSocket = EndAccept(...); // create a base socket handler..... BaseSocket clientSocket = new BaseSocket(); _clients.Add(clientSocket); // bind the ondata event of the client and pass it to the clientondata event of the server. // Start receiving from the socket. clientSocket.Start(clientSocket); // accept new clients. StartAccept(); }
public BaseServer() { _inited = true; _socket = new BaseSocket(); _socket.setServer(this); _socket.setConnectCall(onConnect); _socket.setConnectFailedCall(onConnectFailed); _socket.setCloseCall(onClose); _socket.setCreateResponseFunc(createResponse); NetControl.addSocket(_socket); }
public static byte[] Read(Stream stream, byte[] end) { using (MemoryStream ms = new MemoryStream()) { byte[] data = new byte[1]; int bytes = data.Length; while (bytes > 0 && BaseSocket.findBytes(ms.ToArray(), end, 0) == -1) { bytes = stream.Read(data, 0, data.Length); ms.Write(data, 0, data.Length); } return(ms.ToArray()); } }
/// <summary> /// Performs TCP connection and sets up reader/writer. /// Allows different control port to be used /// </summary> /// <param name="sock"> /// Socket instance /// </param> /// <param name="remoteHost"> /// address of remote host /// </param> /// <param name="controlPort"> /// port for control stream /// </param> /// <param name="timeout"> /// the length of the timeout, in milliseconds /// </param> /// <param name="encoding"> /// encoding to use for control channel /// </param> internal void Initialize(BaseSocket sock, string remoteHost, int controlPort, int timeout, Encoding encoding) { this.remoteHost = remoteHost; this.controlPort = controlPort; this.timeout = timeout; // establish socket connection & set timeouts controlSock = sock; ConnectSocket(controlSock, remoteHost, controlPort); Timeout = timeout; InitStreams(encoding); }
protected void Write(Stream stream, SocketMessager messager) { MemoryStream ms = new MemoryStream(); byte[] buff = Encoding.UTF8.GetBytes(messager.GetCanParseString()); ms.Write(buff, 0, buff.Length); if (messager.Arg != null) { buff = Deflate.Compress(BaseSocket.Serialize(messager.Arg)); ms.Write(buff, 0, buff.Length); } this.Write(stream, ms.ToArray()); ms.Close(); }
public void disconect() { try { baseSocket.disconnect(); } catch { } baseSocket = null; try { baseSocket.onRecive -= onRecive; }catch { } try { baseSocket.onConnect -= onConnect; } catch { } try { baseSocket.onDisconect -= onDisconect; } catch { } try { baseSocket.onSent -= onSent; } catch { } try { remove(); } catch { } }
private void OnPartEdited(BasePart part, BaseSocket socket) { if (part != Part) { return; } if (EditionObject != null) { GameObject Temp = Instantiate(EditionObject, part.transform.position, part.transform.rotation); Destroy(Temp, LifeTime); } }
public async Task <bool> ToggleWirelessSocketState(BaseSocket wirelessSocket) { try { var requestParams = SetPilightQueryParams(wirelessSocket); var request = new HttpRequestMessage(HttpMethod.Get, requestParams); var response = await _httpClient.SendAsync(request); } catch (Exception e) { // nothing to do here } return(true); }
/// <summary> /// Listens for an inbound connection. /// </summary> public override void Accept() { if (m_accept == null) { m_accept = new AsyncSocket(null, this, (bool)m_listener[Options.SSL], false); ((AsyncSocket)m_accept).LocalCertificate = m_listener[Options.LOCAL_CERTIFICATE] as X509Certificate2; Address addr = new Address((string)m_listener[Options.NETWORK_HOST], (int)m_listener[Options.PORT]); m_accept.Accept(addr); } m_accept.RequestAccept(); }
internal void SetSocketTimeout(BaseSocket sock, int timeout) { if (timeout > 0) { try { sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, timeout); sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, timeout); } catch (SocketException exception) { this.log.Warn("Failed to set socket timeout: " + exception.Message); } } }
/// <summary> /// Closes underlying sockets /// </summary> internal override void Close() { try { if (acceptedSock != null) { acceptedSock.Close(); acceptedSock = null; } } finally { sock.Close(); } }
internal override void Close() { try { if (this.acceptedSock != null) { this.acceptedSock.Close(); this.acceptedSock = null; } } finally { base.sock.Close(); } }
internal void Kill() { try { if (controlSock != null) { controlSock.Close(); } controlSock = null; } catch (Exception e) { log.Debug("Killed socket", e); } log.Info("Killed control socket"); }
/// <summary> /// Is the socket occopied in the group buildings? /// </summary> /// <param name="socketInstance">the instance of the socket you are checking.</param> /// <returns></returns> public virtual bool IsGroupSocketOccoupied(BaseSocket socketInstance) { BaseSocket socket; for (int i = 0; i < buildings.Count; i++) { socket = buildings.ElementAt(i).ReturnSocket(socketInstance.transform.position, socketInstance.receiveType); if (socket != null && socket.building != socketInstance.building && !socket.isActive) { return(true); } } return(false); }
public static void OnRecvUDP(byte[] recvBuffer, int length, BaseSocket socket) { //MultiGameView.Log("Recieve collect Player Request ServiceManager:"); byte commandType; //CommonTrace.Log(string.Format("收到UDP:数据类型{0}", packageType)); var binaryHead = PackageHelper.BytesToStuct<PkgHead>(recvBuffer); commandType = binaryHead.MasterMsgType; int ret = binaryHead.DataLength; if (ServiceMap.ContainsKey(commandType)) { ServiceMap[commandType].SaveResponseHandleToInvoke(recvBuffer.Take(ret).ToArray(), socket.GetSocketId(), commandType); } }
/// <summary> /// Performs TCP connection and sets up reader/writer. /// Allows different control port to be used /// </summary> /// <param name="sock"> /// Socket instance /// </param> /// <param name="remoteHost"> /// address of remote host /// </param> /// <param name="controlPort"> /// port for control stream /// </param> /// <param name="timeout"> /// the length of the timeout, in milliseconds /// </param> internal void Initialize(BaseSocket sock, IPAddress remoteHost, int controlPort, int timeout) { this.remoteHost = remoteHost; this.controlPort = controlPort; this.timeout = timeout; log = Logger.GetLogger(typeof(FTPControlSocket)); // establish socket connection & set timeouts controlSock = sock; ConnectSocket(controlSock, remoteHost, controlPort); Timeout = timeout; InitStreams(); ValidateConnection(); }
internal void Kill() { try { if (this.controlSock != null) { this.controlSock.Close(); } this.controlSock = null; } catch (Exception exception) { this.log.Debug("Killed socket", exception); } this.log.Info("Killed control socket"); }
internal FTPControlSocket() { this.log = Logger.GetLogger("FTPControlSocket"); this.synchronizePassiveConnections = false; this.strictReturnCodes = false; this.remoteHost = null; this.remoteAddr = null; this.controlPort = -1; this.controlSock = null; this.timeout = 0; this.writer = null; this.reader = null; this.activePortRange = null; this.activeIPAddress = null; this.nextPort = 0; this.autoPassiveIPSubstitution = false; }
public void AcceptAsync() { if (!IsClient) { var acceptArgs = SocketPool.Pop(); acceptArgs.Completed += OnSocketCompleted; var willRaiseEvent = BaseSocket.AcceptAsync(acceptArgs); if (!willRaiseEvent) { AcceptHandle(acceptArgs); } } else { RaiseFault("Unable to create connections on a client socket."); } }
private void StartReceive() { if (State != ConnectionState.Working) { return; } try { if (!BaseSocket.ReceiveAsync(SocketReceiveArgs)) { ReceiveProcess(SocketReceiveArgs); } } catch { Close(); } }
public static SocketMessager Parse(byte[] data) { if (data == null) { return(new SocketMessager("NULL")); } if (data.Length == 1 && data[0] == 0) { return(SocketMessager.SYS_TEST_LINK); } int idx = BaseSocket.findBytes(data, new byte[] { 13, 10 }, 0); string text = Encoding.UTF8.GetString(data, 0, idx); string[] loc1 = text.Split(new string[] { "\t" }, 4, StringSplitOptions.None); string loc2 = loc1[0]; string loc3 = loc1.Length > 1 ? loc1[1].Replace("\\\\", "\\").Replace("\\t", "\t").Replace("\\n", "\r\n") : null; string loc4 = loc1.Length > 2 ? loc1[2].Replace("\\\\", "\\").Replace("\\t", "\t").Replace("\\n", "\r\n") : null; string loc5 = loc1.Length > 3 ? loc1[3] : null; SocketMessager messager; using (MemoryStream ms = new MemoryStream()) { ms.Write(data, idx + 2, data.Length - idx - 2); messager = new SocketMessager(loc3, loc4, ms.Length > 0 ? BaseSocket.Deserialize(ms.ToArray()) : null); //using (DeflateStream ds = new DeflateStream(ms, CompressionMode.Decompress)) { // using (MemoryStream msOut = new MemoryStream()) { // ds.CopyTo(msOut); // messager = new SocketMessager(loc3, loc4, ms.Length > 0 ? BaseSocket.Deserialize(ms.ToArray()) : null); // } //} } if (int.TryParse(loc2, out idx)) { messager._id = idx; } if (!string.IsNullOrEmpty(loc5)) { DateTime.TryParse(loc5, out messager._remoteTime); } if (messager._arg is Exception) { messager._exception = messager._arg as Exception; } return(messager); }
public Proxy(BaseSocket frontend, BaseSocket backend, BaseSocket control) { m_frontend = frontend; m_backend = backend; m_control = control; }
/// <summary> /// Creating the monitoring socket, this method automaticlly called by the start method /// if you want to receive events that happen before the call to the start mehod call /// this method earlier in your code /// </summary> public void Init() { if (!m_initialized) { // in case the sockets is created in another thread Thread.MemoryBarrier(); ZMQ.SocketMonitor(Socket.SocketHandle, MonitorAddress, m_monitoringEventsHandler.Events); MonitoringSocket = Context.CreatePairSocket(); MonitoringSocket.Connect(MonitorAddress); m_initialized = true; } }
public SocketOptions(BaseSocket socket) { m_socket = socket; }