public generateOKPacket ( int packetNumber, int affectedRows ) : byte[] | ||
packetNumber | int | |
affectedRows | int | |
return | byte[] |
/* * starts the listerner */ public void startInternal(String username, String token, String host) { Mysql x = new Mysql(0, m_writer); // set initial state m_state = State.NOT_CONNECTED; // start socket and wait for incoming client connection // add here multi client stuff m_socket.Start(); TcpClient client = m_socket.AcceptTcpClient(); NetworkStream ns = client.GetStream(); StreamWriter sw = new StreamWriter(ns); sw.AutoFlush = true; if (!ns.CanRead) { Console.WriteLine("Info: Stream no readable...."); return; } var pi = ns.GetType().GetProperty("Socket", BindingFlags.NonPublic | BindingFlags.Instance); var socketIP = ((Socket)pi.GetValue(ns, null)).RemoteEndPoint.ToString(); Console.WriteLine("Connecting client: " + socketIP); // send the server greeting (static for now) handleNotConnected(x, ns, client); ns = client.GetStream(); while(socketCheck(ns)) { Console.WriteLine("Info: Read " + readBytes + " bytes...."); // if not connected, do a straight forward "send a greeting packet" if (m_state == State.NOT_CONNECTED) { Console.WriteLine("Info: Mysqlpot in state NOT CONNECTED, not possible state, error"); } else if (m_state == State.GREETING_PACKET_SEND) { Console.WriteLine("Info: Mysqlpot in state GREETING_PACKET_SEND"); x.handleLoginPacket(data, socketIP, token, username, host); m_state = State.LOGIN_OK; Console.WriteLine("Info: Login packet retrieved, now trying to generate answer packet..."); byte[] okPacket = x.generateOKPacket(x.getPacketNumber(data) + 1, 1); // packetnumber, affeceted lines Console.WriteLine("Info: Now writing OK packet back on the line.."); sw.Write (System.Text.Encoding.UTF8.GetString(okPacket).ToCharArray()); ns = client.GetStream(); } else if (m_state == State.LOGIN_OK) { Console.WriteLine("Info: Mysqlpot in state LOGIN_OK"); byte[] queryString = x.handleQueryPacket(data, socketIP, token, username, host); byte[] answer = x.getAnswerPacket(queryString, x.getPacketNumber(data) + 1); if (answer != null) { ns.Write(answer, 0, answer.Length); // sw.Write (System.Text.Encoding.UTF8.GetString(answer).ToCharArray()); ns = client.GetStream(); } else { Console.WriteLine("Info: Detected no suitable answer for the SQL query"); } } else { Console.WriteLine("Info: Mysqlpot in unknown state"); break; } } Console.WriteLine("Error: Ausbruch aus dem while loop"); ns.Close(); client.Close(); m_socket.Stop(); m_state = State.NOT_CONNECTED; }
/* * starts the listerner */ public void startInternal(String username, String token, String host) { Mysql x = new Mysql(0, m_writer); // set initial state m_state = State.NOT_CONNECTED; // start socket and wait for incoming client connection // add here multi client stuff m_socket.Start(); TcpClient client = m_socket.AcceptTcpClient(); NetworkStream ns = client.GetStream(); StreamWriter sw = new StreamWriter(ns); sw.AutoFlush = true; if (!ns.CanRead) { Console.WriteLine("Info: Stream no readable...."); return; } var pi = ns.GetType().GetProperty("Socket", BindingFlags.NonPublic | BindingFlags.Instance); var socketIP = ((Socket)pi.GetValue(ns, null)).RemoteEndPoint.ToString(); Console.WriteLine("Connecting client: " + socketIP); // send the server greeting (static for now) handleNotConnected(x, ns, client); ns = client.GetStream(); while (socketCheck(ns)) { Console.WriteLine("Info: Read " + readBytes + " bytes...."); // if not connected, do a straight forward "send a greeting packet" if (m_state == State.NOT_CONNECTED) { Console.WriteLine("Info: Mysqlpot in state NOT CONNECTED, not possible state, error"); } else if (m_state == State.GREETING_PACKET_SEND) { Console.WriteLine("Info: Mysqlpot in state GREETING_PACKET_SEND"); x.handleLoginPacket(data, socketIP, token, username, host); m_state = State.LOGIN_OK; Console.WriteLine("Info: Login packet retrieved, now trying to generate answer packet..."); byte[] okPacket = x.generateOKPacket(x.getPacketNumber(data) + 1, 1); // packetnumber, affeceted lines Console.WriteLine("Info: Now writing OK packet back on the line.."); sw.Write(System.Text.Encoding.UTF8.GetString(okPacket).ToCharArray()); ns = client.GetStream(); } else if (m_state == State.LOGIN_OK) { Console.WriteLine("Info: Mysqlpot in state LOGIN_OK"); byte[] queryString = x.handleQueryPacket(data, socketIP, token, username, host); byte[] answer = x.getAnswerPacket(queryString, x.getPacketNumber(data) + 1); if (answer != null) { ns.Write(answer, 0, answer.Length); // sw.Write (System.Text.Encoding.UTF8.GetString(answer).ToCharArray()); ns = client.GetStream(); } else { Console.WriteLine("Info: Detected no suitable answer for the SQL query"); } } else { Console.WriteLine("Info: Mysqlpot in unknown state"); break; } } Console.WriteLine("Error: Ausbruch aus dem while loop"); ns.Close(); client.Close(); m_socket.Stop(); m_state = State.NOT_CONNECTED; } // start()