private bool versionExchangeSwitch = false; // false -> From server to client, true -> From client to server #endregion Fields #region Constructors public Client(TCPSocket sock) { Log.Info("Client", "Creating new connection to EVEmu Server"); connection = new TCPSocket(26000, false); if (connection.Connect("mmoemulators.com") == false) { Log.Error("Client", "Cannot connect to EVEmu Server on port 25999"); CloseConnection(); return; } clientPacketizer = new StreamPacketizer(); serverPacketizer = new StreamPacketizer(); socket = sock; serverReceive = new AsyncCallback(ServerAsyncReceive); clientReceive = new AsyncCallback(ClientAsyncReceive); // Give time to the socket Thread.Sleep(2000); AsyncState serverState = new AsyncState(); connection.Socket.BeginReceive(serverState.buffer, 0, 8192, SocketFlags.None, serverReceive, serverState); AsyncState clientState = new AsyncState(); socket.Socket.BeginReceive(clientState.buffer, 0, 8192, SocketFlags.None, clientReceive, clientState); }
static void Main(string[] args) { Log.Init("packet-editor"); Log.Info("Main", "Starting listening socket"); socket = new TCPSocket(26000, false); if (socket.Listen(5) == false) { Log.Error("Main", "Cannot start listening socket on port 26000."); Log.Info("Main", "You should have your EVEmu server working on port 25999"); Log.Info("Main", "and port 26000 free of any server."); while (true) Thread.Sleep(1); } Log.Info("Main", "Listening socket started succesful"); while (true) { Thread.Sleep(1); while (clientList.Count > 0) Thread.Sleep(10); TCPSocket client = socket.Accept(); if (client != null) { clientList.Add(new Client.Client(client)); Log.Debug("Main", "Incoming connection, waiting until it finishes"); } } }
private void Send(byte[] data, TCPSocket to) { byte[] packet = new byte[data.Length + 4]; Array.Copy(data, 0, packet, 4, data.Length); Array.Copy(BitConverter.GetBytes(data.Length), packet, 4); to.Send(packet); }
public TCPSocket(TCPSocket from, bool socket_listening) { sock = from.Socket; listening = socket_listening; }