public bool Send(ITransferable packet, object userData = null) { if (_connected == 0) { return(false); } try { //Send data byte[] byteBuffer = packet.Serialize(); int dataLength = byteBuffer.Length; _networkStream.Write(byteBuffer, 0, dataLength); //Fire DataSent event if (DataSent != null) { DataSent(packet, userData); } return(true); } catch (Exception ex) { if (DataSendError != null) { DataSendError(packet, userData, ex); } Disconnect(); } return(false); }
public bool Send(TCPClientEx tcpClient, ITransferable packet, object userData = null) { if (!tcpClient.Connected) { return(false); } try { //Send data byte[] byteBuffer = packet.Serialize(); int dataLength = byteBuffer.Length; ((TcpClient)tcpClient).GetStream().Write(byteBuffer, 0, dataLength); //Fire DataSent event if (ClientDataSent != null) { ClientDataSent(tcpClient, packet, userData); } return(true); } catch (Exception ex) { if (ClientDataSendError != null) { ClientDataSendError(tcpClient, packet, userData, ex); } } return(false); }
public void Send(int clientId, ITransferable packet) { //Serialize data byte[] dataToSend = packet.Serialize(); //Send data Send(clientId, dataToSend); }
public void Send(ITransferable packet) { //Serialize data byte[] dataToSend = packet.Serialize(); //Send data Send(dataToSend); }
public bool Send(ITransferable packet, object userData = null) { if (_connected == 0) { return false; } try { //Send data byte[] byteBuffer = packet.Serialize(); int dataLength = byteBuffer.Length; _networkStream.Write(byteBuffer, 0, dataLength); //Fire DataSent event if (DataSent != null) { DataSent(packet, userData); } return true; } catch (Exception ex) { if (DataSendError != null) { DataSendError(packet, userData, ex); } Disconnect(); } return false; }
public bool Send(TCPClientEx tcpClient, ITransferable packet, object userData = null) { if (!tcpClient.Connected) { return false; } try { //Send data byte[] byteBuffer = packet.Serialize(); int dataLength = byteBuffer.Length; ((TcpClient) tcpClient).GetStream().Write(byteBuffer, 0, dataLength); //Fire DataSent event if (ClientDataSent != null) { ClientDataSent(tcpClient, packet, userData); } return true; } catch (Exception ex) { if (ClientDataSendError != null) { ClientDataSendError(tcpClient, packet, userData, ex); } } return false; }