Пример #1
0
 /// <summary>
 /// Gracefully closes the network client
 /// </summary>
 public void Close()
 {
     if (MapleSocket != null)
     {
         MapleSocket.Shutdown(SocketShutdown.Both);
     }
 }
Пример #2
0
 /// <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
     }
 }
Пример #3
0
        /// <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
            }
        }
Пример #4
0
        /// <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
                }
            }
        }
Пример #5
0
        /// <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);
            }
        }