Sunday, 18 May 2025

Establish Socket Connection Between AWS [EC2 UBUNTU] And Computer

  


AWS EC2 Ubuntu Setup :-

https://www.youtube.com/watch?v=uWFKq4KuRb0

Download PuTTY and FileZilla

https://www.putty.org/

https://filezilla-project.org/


Subscribe my Channel:-

http://www.youtube.com/user/SanketRooney?sub_confirmation=1

Gaming Channel:-

https://www.youtube.com/@unpoggaming9532

Gaming Instagram:- (@unpog.gaming)

https://www.instagram.com/unpog.gaming/

Facebook Page:-

https://www.facebook.com/UnpossibleNS

Twitter Account:-

https://twitter.com/UnpossiblePOG

Blog:-

https://unpossiblepog.blogspot.com/

Website:-

https://unpossiblepog.com/

========================

Code :

Server.java

import java.io.*;

import java.net.*;

public class Server {

public static void main(String[] args) {

int port = 5000;

try (ServerSocket serverSocket = new ServerSocket(port)) {

System.out.println("Server started. Waiting for client...");

Socket socket = serverSocket.accept();

System.out.println("Client connected: " + socket.getInetAddress());

// Input from client

BufferedReader clientInput = new BufferedReader(new InputStreamReader(socket.getInputStream()));

// Output to client

PrintWriter clientOutput = new PrintWriter(socket.getOutputStream(), true);

// Input from server console

BufferedReader serverConsole = new BufferedReader(new InputStreamReader(System.in));

// Create a thread to receive messages from the client

Thread receiveThread = new Thread(() -> {

String messageFromClient;

try {

while ((messageFromClient = clientInput.readLine()) != null) {

System.out.println("Client: " + messageFromClient);

}

} catch (IOException e) {

System.out.println("Connection closed.");

}

});

receiveThread.start();

// Main thread: send messages from server to client

String messageToClient;

while ((messageToClient = serverConsole.readLine()) != null) {

clientOutput.println(messageToClient);

}

} catch (IOException e) {

e.printStackTrace();

}

}

}

-------------------------------------------

Client.java

import java.io.*;

import java.net.*;

public class Client {

public static void main(String[] args) {

String host = "_________"; // Replace with your EC2 IP

int port = 5000;

try (Socket socket = new Socket(host, port)) {

System.out.println("Connected to server.");

// Input from server

BufferedReader serverInput = new BufferedReader(new InputStreamReader(socket.getInputStream()));

// Output to server

PrintWriter serverOutput = new PrintWriter(socket.getOutputStream(), true);

// Input from client console

BufferedReader clientConsole = new BufferedReader(new InputStreamReader(System.in));

// Thread to receive messages from server

Thread receiveThread = new Thread(() -> {

String messageFromServer;

try {

while ((messageFromServer = serverInput.readLine()) != null) {

System.out.println("Server: " + messageFromServer);

}

} catch (IOException e) {

System.out.println("Connection closed.");

}

});

receiveThread.start();

// Main thread: send messages from client to server

String messageToServer;

while ((messageToServer = clientConsole.readLine()) != null) {

serverOutput.println(messageToServer);

}

} catch (IOException e) {

e.printStackTrace();

}

}

}

========================

I was wondering if we could communicate between AWS operating system and PC using command prompt. Found out that this is possible. All we need to do is little bit of setup. The main advantage of using sockets is that once the connection is established, showing the message sent from server to client or vice-versa will not require any triggers like auto-refresh or button click etc. Sockets will handle the rest. Once sockets receives message, we can make program do all sorts of things like like creating new files, deleting files, showing files list etc. Any ways, our task is to establish connection using java sockets and that’s what we are going to do in this video.

In setup, our server will be AWS cloud server more specifically Elastic Compute Cloud, in short EC2. I installed ubuntu operating system in it. Remember that EC2 does not provide user interface to interact with files inside OS, so we shall use commands instead. Here, we shall not do a server setup from scratch. The server setup tutorial links are given in the description.

For client device, we are going to use windows machine which has Java already installed it, so make sure that you have that as well.

First, we shall need a PPK file. With that file, we can connect AWS server’s file system via FILEZILLA and also to run commands using PuTTY terminal. So, make sure that you installed them on you computer as well.

Let’s create KEY PAIR to download ppk file. Follow my steps.

[

From your AWS dashboard, click on EC2 -> Instances -> Key Pairs -> Create key pair

]

Make sure that pair type is RSA and file format is .ppk. Give any random name.

Once created, file will be downloaded automatically.

I already created key pair, so I am going to use that.

Next part is to enable port number 5000.

To create it, follow my steps.

[

Go to your EC2 Console

Select your instance → Networking → Security Groups

Click Inbound rules → Edit

Add a rule:

Type: Custom TCP

Port: 5000 (or any port you use)

Source: Your IP (or 0.0.0.0/0 for testing, but this is insecure)

]

Since I am not sure which group allows access, I am gonna create it in both.

Let’s connect ubuntu server using command prompt. To do that, open PuTTY.

Add IP Address, put 22 as a port number.

Select SSH radio button.

From the left side category, inside connection, go to select SSH, Auth, Credentials.

Select PPK file.

And click on open.

[How to know if ubuntu]

First we shall install Java.

sudo apt install openjdk-17-jdk.

To connect via FTP, use same credentials that we used for connecting server via putty.

Reach to var/www/ and create a folder where we are going to upload java file.

Let’s upload Server.java file. Code link is in the description.

Let’s go inside java-code folder.

Because the folder does not have permission, java file is no uploading. So reach to parent folder via putty terminal give edit permission to java-code folder.

Now, our server is ready.

I created a Client.java file. Code link is in the description.

Set AWS’s public IP as a value of String host variable.

In command prompt of client which is a windows system, we shall reach to a location where Client.java file is present.

Lets run client script.

And as you can see, whatever we type in command prompt from client reaches to server and vice-versa.


Wednesday, 22 January 2025

How To Register | create360degree.com


 

Open the browser and type in the URL, create 3 60 degree dot com.

Registered user can store his own 360 permanently. Also, 3 slots are given for free. For

 more information, click on option appeared at the top right corner.
Click on Register.

There are two methods to create an account.
One is by filling the registration form.
Email will be used as a username for login in future, so make sure to add a valid email address.
Once verified, you will receive an email. And in that email, there will be a link. By clicking on it, you will be able to login.
Second way is to login using a google account. We only store your email address, because the email is from google, it will be automatically verified, plus no need to add password every time you have to login.

Just click on Register With Google, you will be asked to login or choose gmail address. Once logged in, you will be redirected to your dashboard.

Sunday, 3 November 2024

create360degree.com | Features | Registered User vs Guest User

 


Unlocking the Full Potential of create360degree.com

create360degree.com offers a fantastic experience for everyone, but registering for a free account opens up even more creative possibilities! Let's explore some of the features available to both guests and registered users, and see how creating an account enhances your experience.

Feature 1: Easy Registration, Powerful Creation

Guests can create stunning 360 experiences using still images. However, registered users can take their creativity a step further by uploading videos and then selecting the perfect frames for their 360 masterpiece. Registering is quick and easy, you can either use your email address or conveniently sign up with your Google account.

Feature 2: Save Your Creations Forever

Guest creations are automatically saved for 90 minutes, allowing you to explore and share them with others. Registered users enjoy the incredible benefit of permanent storage for their 360 creations. Plus, you get three free storage slots to keep your masterpieces organised and accessible anytime. Need more space? Additional slots are available at an affordable price.

Feature 3: Customization and Control

Both guests and registered users can personalise their 360 experiences with features like:

  • Image rotation

  • Private accessibility as default

  • Rearrangement of images

  • Adding hotspots for interactive elements

Registered users gain even more control:

  • Password protection

  • Privacy settings (public, private, embeddable)

  • Categorization for easy discovery (educational, creativity, location, product)

  • Effortless Hotspot Creation: Search and import existing 360s to create internal links as hotspots, saving you time and effort.

  • Seamless Cross-Linking of hotspot: Add your current 360 as a hotspot to other creations on the platform, building connections between your work.

Feature 4: Preview and Publish with Confidence

Everyone can preview their 360 creation, ensuring it looks and functions exactly as intended.

Ready to Unleash Your Creativity?

Registering for a free account on create360degree.com unlocks a world of creative possibilities. From video uploads and permanent storage to advanced customization tools and effortless hotspot creation, you'll be well on your way to crafting stunning 360 experiences. Sign up today and get started!

Sunday, 22 September 2024

create360degree.com | Bring 3D Objects OR Environment To Life



Ever wanted to show off an object from every angle? create360degree.com lets you create stunning 360° experiences in just 5 easy steps:

  1. Capture your object: Use your phone or camera to take pictures at different angles.
  2. Upload in seconds: Upload your photos effortlessly.
  3. Add interactive hotspots (optional): Want to showcase details or link to other objects? Add hotspots with text, images, or even links!
  4. Preview your masterpiece: Instantly see how your 360° experience will look.
  5. Share with the world: Share your creation with friends, family, or on social media!

Get 3 free slots to create your first 360° experiences! Sign up now at create360degree.com

Friday, 29 March 2024

MySQL: How to Select Entire Row with MAX in Group By (Subquery Method)

 


Code : 

SELECT potential_customers.* from potential_customers where concat(potential_customers.customer_id,'-',potential_customers.next_call) IN

(SELECT concat(PC1.customer_id,'-',MAX(PC1.next_call)) FROM `potential_customers` PC1 GROUP by customer_id);

========================

Subscribe my Channel:-

http://www.youtube.com/user/SanketRooney?sub_confirmation=1


Gaming Channel:-

https://www.youtube.com/@unpoggaming9532


Gaming Instagram:- (@unpog.gaming)

https://www.instagram.com/unpog.gaming/

Facebook Page:-

https://www.facebook.com/UnpossibleNS

Twitter Account:-

https://twitter.com/UnpossiblePOG

Blog:-

https://unpossiblepog.blogspot.com/

Website:-

https://unpossiblepog.com/

========================

Hey guys, there is a limitation in MYSQL, where you use group by and wanted max value, but when you try to fetch a row ID or any other column, it fails.

For example, there is one table on the left side called “potential_customers”, and on the right side, I wrote one query which returns maximum NEXT_CALL value for each customer_id.

So, in current example I wanted row ID 2 & 6.

But if I need ID or whole row, it fails even when you use order by column_name DESC.

Thankfully there is a workaround for this which is to use the combination of subquery and concat.

First, let’s alter the query, to concat customer_id and max of next call. Remove all order by if there is any.

Put that query is sub-query by adding rounded brackets around it.

Now, write a select query before sub query, & in where condition, use concat of required column. Don’t forget to use “IN” keyword.

And as you can see, it returns row ID that we need.

You can call whole column if you want.

So that’s it. Code link is given in the description.

Thanks for watching. Like, Share and Subscribe.

Thursday, 12 October 2023

Flutter | Create A Scrollable Pagination | Horizontal

 



Flutter | Create A Scrollable Pagination | Horizontal

-------------------------------

Link 1 Code (Data table) :-

https://unpossiblepog.blogspot.com/2023/10/Flutter-Datatable-With-Horizontal-Scroll-Display-Data-From-Rest-API.html

Note : Watch the video to understand how the code was made so that you can easily make changes as per your need.

Subscribe my Channel:-

http://www.youtube.com/user/SanketRooney?sub_confirmation=1

Gaming Channel:-

https://www.youtube.com/@unpoggaming9532

Gaming Instagram:- (@unpog.gaming)

https://www.instagram.com/unpog.gaming/

Facebook Page:-

https://www.facebook.com/UnpossibleNS

Twitter Account:-

https://twitter.com/UnpossiblePOG

Blog:-

https://unpossiblepog.blogspot.com/

Website:-

https://unpossiblepog.com/

========================

Important Note : Make sure to add “http: any” dependency in pubspec.yaml file.

main.dart code :

import 'package:flutter/material.dart';

import 'package:flutter/foundation.dart';

import 'package:http/http.dart' as http;

import 'dart:convert';

void main() {

runApp(const showListingPage());

}

List? dataList;

int totalPages = 0;

String filterListingString = "";

class showListingPage extends StatelessWidget {

const showListingPage({Key? key}) : super(key: key);

@override

Widget build(BuildContext context) {

return MaterialApp(

title: 'View All',

routes: {

},

theme: ThemeData(

primarySwatch: Colors.blue,

),

home: const ViewAllPage(title: 'View All'),

);

}

}

class ViewAllPage extends StatefulWidget {

const ViewAllPage({Key? key, required this.title}) : super(key: key);

final String title;

@override

State<ViewAllPage> createState() => _ViewAllPageStateViewAll();

}

class _ViewAllPageStateViewAll extends State<ViewAllPage> {

int total_records = 0;

List _posts = [];

int curr_page = 1;

int count_per_page = 2;

void loadDataFromAPI(int page_number,int per_page) async {

try {

final res =

await http.get(Uri.parse("http://unpossiblepog.com/apis/getFlutterPaginationApi.php?page="+page_number.toString()+"&per_page="+per_page.toString()));

setState(() {

_posts = json.decode(res.body);

if(_posts.length>0)

{

dataList = _posts;

total_records = int.parse(_posts[0]['count']);

totalPages =

(total_records / count_per_page).ceil();

}

});

} catch (err) {

if (kDebugMode) {

print('Something went wrong');

}

}

}

double numberFunction(int i)

{

int nun = i.toString().length;

String finalString = "0.";

for(int j=0;j<nun;j++)

{

finalString += "1";

}

finalString += "0";

return double.parse(finalString);

}

MaterialColor getColorForThis(int i)

{

MaterialColor c=Colors.green;

if(i==curr_page)

{

c=Colors.blue;

}

return c;

}

@override

Widget build(BuildContext context) {

return Scaffold(

appBar: AppBar(

title: const Text('View All'),

centerTitle: true,

actions: <Widget>[],

),

body: ListView(children: <Widget>[

SingleChildScrollView(

padding: const EdgeInsets.all(8.0),

scrollDirection: Axis.horizontal,

child: DataTableOutputViewAll(),

),

SingleChildScrollView(

scrollDirection: Axis.horizontal,

child: Row(children: <Widget>[

SizedBox(

width: MediaQuery.of(context).size.width * 0.05,

),

//totalPages

for(var i=0;i<totalPages;i++) ...[

Container(

width: MediaQuery.of(context).size.width * numberFunction(i) * 1.5,

margin: const EdgeInsets.fromLTRB(0, 0, 10, 0),

height: 50.0,

child: RaisedButton(color: getColorForThis(i+1),

child: new Text(""+(i+1).toString(),style: TextStyle(color: Colors.white),),

onPressed: (){

curr_page = i+1;

loadDataFromAPI(i+1,count_per_page);

},

),

)

],

SizedBox(

width: MediaQuery.of(context).size.width * 0.05,

),

],),

)

]),

);

}

@override

void initState() {

super.initState();

dataList = null;

totalPages = 0;

if (dataList == null) {

loadDataFromAPI(1,count_per_page);

}

}

@override

void dispose() {

super.dispose();

}

}

class DataTableOutputViewAll extends StatelessWidget {

const DataTableOutputViewAll({Key? key}) : super(key: key);

List<InlineSpan> getData(Map<String, String> amount_entry_details) {

List<InlineSpan> temp = [];

amount_entry_details.forEach((k, v) => {

temp.add(

TextSpan(

style: const TextStyle(

color: Colors.black,

),

children: <TextSpan>[

TextSpan(

text: k + ' : ',

style: const TextStyle(fontWeight: FontWeight.bold)),

TextSpan(text: v + '\n'),

],

),

),

});

return temp;

}

@override

Widget build(BuildContext context) {

List<DataRow> rows = [];

if (dataList != null) {

for (int i = 0; i < dataList!.length; ++i) {

rows.add(DataRow(

cells: <DataCell>[

DataCell(Text(

'' + dataList![i]['language'].toString(),

style: TextStyle(fontSize: 15)),onTap: (){

}),

DataCell(

Text(

'' + dataList![i]['post_title'].toString(),

style: TextStyle(fontSize: 15)),onTap: (){

}),

],

));

}

}

return DataTable(

columns: const <DataColumn>[

DataColumn(

label: Text(

'Language',

style: TextStyle(fontStyle: FontStyle.italic),

),

numeric: false,

),

DataColumn(

label: Text(

'Title',

style: TextStyle(fontStyle: FontStyle.italic),

),

numeric: false,

),

],

rows: rows,

);

}

}

========================

Hey guys.

I have made a code which will generate a scrollable pagination feature in Flutter App. Today I am going to be sharing it’s code with you guys. Let’s get started.

The tutorial is divided into 2 phases.

1st is displaying data in data table.

2nd is adding scrollable pagination at bottom.

To execute the phase 1, what we shall do is a copy-paste from my blog. The link is given in the description with a title as “Link 1 Code (Data table)”

Instructions are given, we just have to follow it.

In new project, we shall add a dependency.

Make sure that it is at the same level as a flutter text.

Then, you can download that dependency using the command.

Copy-paste the whole code and paste it in main.dart file.

Let’s run the project.

You will see the data in data-table which itself is a scrollable.

The data is coming from the Rest API.

Each row is sending the total number of rows in count. Every API may send total row count in different key and at difference places or won’t send it at all so take a note to make sure it sends a total number of rows.

Lets begin a phase 2.

We already created a code to get total pages which will be shown at the bottom of an APP page.

Here, we will add another singlechildscrollview.

We will allow it to scroll horizontally.

Add a row as a child, advantage is that we can add multiple children in it which will be our pagination buttons.

The sizedbox is required, let me tell you why in a minute.

Let’s add a width in it.

Here you can see that the text ABC is appearing the right side of a screen.

We will do some mathematics to make it at the level of a data table.

Then I will be using a for loop.

Inside that will be our page buttons.

We will be using container with some specific width. This width will be dynamic, depending upon the length of a page number. I shall explain it in a minute.

For a button, we will be using a RaisedButton as a child.

Inside RaisedButton, we will temporarily add a 1 text.

OnPressed function is necessary.

Button appears.

We shall temporarily change the page count as 10 in for loop.

We will create a function called numberFunction which will be deciding the width of every button.

Let’s create that function which will return a double value.

Whenever the length of a page number changes, so will the float amount of that button.

Now the width looks OK.

Add i+1 as a text which will accurately display page number.

On pressed, we will change the current page number to highlight it.

Let’s make number’s color as white.

Because there are only 15 records, there are only 2 pages.

So let’s make 2 records per page.

We will add sizedBox at the end of container too to make some spacing from the right side.

To make some gap between buttons, we shall add margin as 10 from right side.

Set height property as 50.

To change content when clicked on button, call the loadDAtaFromAPI method on button’s onPressed function.

In pagination, there is always a feature will tells users the current page by highlighting it.

So let’s change the color of current page.

Because it is dynamic, we shall create another function called getColorForThis.

It will return a color by checking if that page number matches with current one.

There is some error.

So the return type should be MaterialColor.

Let’s run the project again.

You will see the pagination as expected. It is scrollable and go up to infinite.

There is a link in description called “Link 2 Code (Final Pagination)”. You can refer that if your code is not executing as expected.

Enjoy the code, play with it to create your own version.

Thanks for watching. Like, Share and Subscribe.

Saturday, 7 October 2023

Flutter | Data-Table With Horizontal Scroll | Display Data From Rest API




1. Create a new project

-----------------------------

2. Add following line in dependencies (pubspec.yaml).

http: any

-----------------------------

3. Click on PUB GET button, or enter the command "flutter pub get" in terminal.

-----------------------------

4. Copy-paste the following code.


import 'package:flutter/material.dart';

import 'package:flutter/foundation.dart';

import 'package:http/http.dart' as http;

import 'dart:convert';

void main() {

  runApp(const showListingPage());

}

List? dataList;

int totalPages = 0;

String filterListingString = "";

class showListingPage extends StatelessWidget {

  const showListingPage({Key? key}) : super(key: key);

  @override

  Widget build(BuildContext context) {

    return MaterialApp(

      title: 'View All',

      routes: {

      },

      theme: ThemeData(

        primarySwatch: Colors.blue,

      ),

      home: const ViewAllPage(title: 'View All'),

    );

  }

}

class ViewAllPage extends StatefulWidget {

  const ViewAllPage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override

  State<ViewAllPage> createState() => _ViewAllPageStateViewAll();

}

class _ViewAllPageStateViewAll extends State<ViewAllPage> {


  int total_records = 0;

  List _posts = [];

  int curr_page = 1;

  int count_per_page = 10;

  void loadDataFromAPI(int page_number,int per_page) async {

    try {

      final res =

      await http.get(Uri.parse("http://unpossiblepog.com/apis/getFlutterPaginationApi.php?page="+page_number.toString()+"&per_page="+per_page.toString()));

      setState(() {

        _posts = json.decode(res.body);

        if(_posts.length>0)

        {

          dataList = _posts;

          total_records = int.parse(_posts[0]['count']);

          totalPages =

              (total_records / count_per_page).ceil();

        }

      });

    } catch (err) {

      if (kDebugMode) {

        print('Something went wrong');

      }

    }

  }



  @override

  Widget build(BuildContext context) {

    return Scaffold(

      appBar: AppBar(

        title: const Text('View All'),

        centerTitle: true,

        actions: <Widget>[],

      ),

      body: ListView(children: <Widget>[

        SingleChildScrollView(

          padding: const EdgeInsets.all(8.0),

          scrollDirection: Axis.horizontal,

          child: DataTableOutputViewAll(),

        ),

      ]), 

    );

  }

  @override

  void initState() {

    super.initState();

    dataList = null;

    totalPages = 0;

    if (dataList == null) {

      loadDataFromAPI(1,count_per_page);

    }

  }

  @override

  void dispose() {

    super.dispose();

  }


}

class DataTableOutputViewAll extends StatelessWidget {

  const DataTableOutputViewAll({Key? key}) : super(key: key);

  List<InlineSpan> getData(Map<String, String> amount_entry_details) {

    List<InlineSpan> temp = [];

    amount_entry_details.forEach((k, v) => {

      temp.add(

        TextSpan(

          style: const TextStyle(

            color: Colors.black,

          ),

          children: <TextSpan>[

            TextSpan(

                text: k + ' : ',

                style: const TextStyle(fontWeight: FontWeight.bold)),

            TextSpan(text: v + '\n'),

          ],

        ),

      ),

    });

    return temp;

  }

  @override

  Widget build(BuildContext context) {

    List<DataRow> rows = [];

    if (dataList != null) {

      for (int i = 0; i < dataList!.length; ++i) {

        rows.add(DataRow(

          cells: <DataCell>[

            DataCell(Text(

                '' + dataList![i]['language'].toString(),

                style: TextStyle(fontSize: 15)),onTap: (){

            }),

            DataCell(

                Text(

                    '' + dataList![i]['post_title'].toString(),

                    style: TextStyle(fontSize: 15)),onTap: (){

            }),

          ],

        ));

      }

    }

    return DataTable(

      columns: const <DataColumn>[

        DataColumn(

          label: Text(

            'Language',

            style: TextStyle(fontStyle: FontStyle.italic),

          ),

          numeric: false,

        ),

        DataColumn(

          label: Text(

            'Title',

            style: TextStyle(fontStyle: FontStyle.italic),

          ),

          numeric: false,

        ),

      ],

      rows: rows,

    );

  }

}


x