示例#1
0
        /// <summary>
        /// Creates a new Connection witht he given information
        /// </summary>
        /// <param name="dataStream">The Socket of the connection</param>
        /// <param name="connectionID">The id of the connection</param>
        public ConnectionInformation(Socket dataStream, int connectionID, SocketManager manager, IDataParser parser, string ip, byte[] buffer)
        {
            this.parser = parser;
            this.buffer = buffer;
            this.manager = manager;
            this.dataSocket = dataStream;
            this.dataSocket.SendBufferSize = GameSocketManagerStatics.BUFFER_SIZE;
            this.ip = ip;
            this.connectionID = connectionID;
            this.sendCallback = new AsyncCallback(sentData);
            this.receiveCallback = new AsyncCallback(incomingDataPacket);

            if (connectionChanged != null)
                connectionChanged.Invoke(this, ConnectionState.open);
        }
示例#2
0
		internal virtual void Prepare(Socket socket, object asyncState, AsyncCallback asyncCallback)
		{
			base.Prepare(socket, asyncState, asyncCallback);

			/*TO-DO: Recycle these fields:
				private GCHandle[] m_GCHandles;  !!!
				private OverlappedCache m_Cache; !!! */

			this.m_UnmanagedBlob = null;
			this.m_OverlappedEvent = null;
			this.m_DisableOverlapped = false;
			this.m_Cache = null;
			this.m_GCHandles = null;
			this.m_UseOverlappedIO = (Socket.UseOverlappedIO || socket.UseOnlyOverlappedIO);
			this.m_CleanupCount = (m_UseOverlappedIO ? 1 : 2);
		}
示例#3
0
 /// <summary>
 /// Destroys the current connection manager and disconnects all users
 /// </summary>
 public void destroy()
 {
     this.acceptConnections = false;
     try
     {
         this.connectionListener.Dispose();
     }
     catch { }
     this.connectionListener = null;
     //if (activeConnections != null)
     //{
     //    List<ConnectionInformation> connections = new List<ConnectionInformation>(activeConnections.Count);
     //    foreach (ConnectionInformation item in activeConnections.Values)
     //    {
     //        connections.Add(item);
     //    }
     //    foreach (ConnectionInformation item in connections)
     //    {
     //        item.disconnect();
     //    }
     //    activeConnections = null;
     //}
 }
示例#4
0
 /// <summary>
 /// Prepares the socket for connections
 /// </summary>
 private void prepareConnectionDetails()
 {
     connectionListener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     connectionListener.NoDelay = disableNagleAlgorithm;
     try
     {
         connectionListener.Bind(new IPEndPoint(IPAddress.Any, portInformation));
     }
     catch (SocketException ex)
     {
         throw new ModuleInitializationException(string.Format("The socket could not be initialized because there is already a socket listening on port {0}. The socket threw the following exception: {1}{2}", portInformation, Environment.NewLine, ex.ToString()));
         //throw new SocketInitializationException(ex.Message);
     }
 }