/// <summary> /// Gracefully closes the network client /// </summary> public void Close() { if (MapleSocket != null) { MapleSocket.Shutdown(SocketShutdown.Both); } }
/// <summary> /// Connects to the provided endpoint /// </summary> /// <param name="ep">The endpoint to connect to</param> public void Connect(IPEndPoint ep) { try { MapleSocket.Connect(ep); } catch (SocketException sEx) { //TODO: Handle exception } }
/// <summary> /// Connects to the provided IP address and port /// </summary> /// <param name="ip">The IP address to connect to</param> /// <param name="port">The port on the IP address to connect to</param> public void Connect(string ip, ushort port) { IPAddress ipAddress; if (!IPAddress.TryParse(ip, out ipAddress)) { throw new NetworkingException("The provided IP address cannot be parsed.", 1001); } try { MapleSocket.Connect(ipAddress, port); } catch (SocketException sEx) { //TODO: Handle exception } }
/// <summary> /// Sends raw data onto the Socket /// </summary> public void Send(ref byte[] data, int length) { if (!MapleSocket.Connected) { return; } int sent = 0; while (sent < length) { try { sent += MapleSocket.Send(data, length, SocketFlags.None); } catch (SocketException sEx) { //TODO: Handle exception } } }
/// <summary> /// Receives data from the underlying Socket /// </summary> public void Receive() { if (!Connected) { //TODO: Notify main thread of possible error return; } int received = 0; try { received = MapleSocket.Receive(DataBuffer, BufferOffset, DataBuffer.Length - BufferOffset, SocketFlags.None); } catch (SocketException sEx) { //TODO: Handle exception } if (received > 0) { ProcessRawData(received); } }