public void SendMessage(string message) { PackageData data = new PackageData(); data.Add("Server"); data.Add(message); Send(data); }
public PackageData Receive() { PackageData ret = new PackageData(); int rc; byte[] buffer = new byte[PackageData.BufferSize]; if (_protocolType == ProtocolType.Tcp) { while (true) { try { rc = _socket.Receive(buffer); ret.Add(buffer, rc); if (rc == PackageData.BufferSize) { continue; } break; } catch (ObjectDisposedException ode) { break; } catch (SocketException e) { } } } return(ret); }
public PackageData Receive() { PackageData ret = new PackageData(); try { while (true) { int rc = 0; byte[] buffer = new byte[PackageData.BufferSize]; IPEndPoint fromEndPoint = new IPEndPoint(_destination.Address, 0); EndPoint castFromEndPoint = fromEndPoint; rc = _socket.ReceiveFrom(buffer, ref castFromEndPoint); fromEndPoint = (IPEndPoint)castFromEndPoint; ret.Add(buffer, rc); if (rc == PackageData.BufferSize) { continue; } break; } } catch (Exception e) { } return(ret); }
public void Close() { if (_socket != null) { PackageData test = new PackageData(); test.Add("command"); test.Add("shutdown"); test.Add(Name); Send(test); _receiveThread.Abort(); _socket.Shutdown(SocketShutdown.Both); _socket.Close(); } }