public void BeginReceiveCallBack(IAsyncResult ar) { try { if (socket.Connected) { socket.EndReceive(ar); byte[] buff = new byte[BuffMaxLength]; int rec = socket.Receive(buff, buff.Length, 0); if (rec < buff.Length) { Array.Resize <byte>(ref buff, rec); } XMLEventArgs args = new XMLEventArgs(Encoding.ASCII.GetString(buff)); this.OnReceive.Invoke(args); log.Add("Server - BeginReceiveCallBack received: ", ASCIIEncoding.ASCII.GetString(buff), LogType.Passo); } else { OnClose.Invoke(new CloseEventArgs()); } } catch (Exception ex) { log.Add("Server - BeginReceiveCallBack Exception", ex.Message, LogType.Exception); } finally { if (socket.Connected) { socket.BeginReceive(new byte[] { 0 }, 0, 0, 0, BeginReceiveCallBack, 0); } } }
public void SendBytes(byte[] Bytes) { try { if (socket.Connected) { socket.Send(Bytes); XMLEventArgs args = new XMLEventArgs(Encoding.ASCII.GetString(Bytes)); this.OnSend.Invoke(args); } } catch (Exception ex) { log.Add("Send Exception", ex.Message, LogType.Exception); } }
public void SendText(string texto) { try { if (socket.Connected) { byte[] buffer = Encoding.ASCII.GetBytes(texto + "\0"); socket.Send(buffer); XMLEventArgs args = new XMLEventArgs(Encoding.ASCII.GetString(buffer)); this.OnSend.Invoke(args); } } catch (Exception ex) { log.Add("Send Exception", ex.Message, LogType.Exception); } }
private void XMLSocket_OnSend(XMLEventArgs args) { }
private void XMLSocket_OnReceive(XMLEventArgs args) { }