#I need help with building a bidding app

1 messages ยท Page 2 of 1

foggy nymph
#

He's in denmark, my dream country

#

but messaging him require money on linked in sth and it's very expensive for me in the 3rd world

#

may be i will do very simple app

foggy nymph
#

@forest lion I have decided to submit the minecraft command-like app

#

@forest lion I have decided to ignore Serialization

sick thistle
# foggy nymph

Hello bro, myself saj. Professional software engineer I helped students in their studies like programming websites mobile apps. So if you want help in your assignment you can tell me

foggy nymph
# sick thistle Hello bro, myself saj. Professional software engineer I helped students in their...

oh i really need help right now in JavaFX . I have decided to study JavaFX on a book of Jenkov, however i face a lots of challenges. Particularly, i want to use borderpane for my app, and the right side of it is supposed to contains a constant self update display of a ConcurrentHashMap. But i really dont know how to do it. Please help.
By the way i am also facing deadline in 31 may, so we have 10 more days.

#

in my bidding project, i want the right side of it is like : Name of the person, below it is his items
for example it should be like
Anna sells:

  • apple
  • banana
  • orange
    Bob sells:
  • cake
  • bread
  • flour
    Collin sells:
  • apartments
  • flat

like that

#

and i want it to self update

lethal tinselBOT
#

I uploaded your attachments as Gist. This makes them more accessible, for example to mobile users.

foggy nymph
#

@sick thistle btw this is my current project

#

@sick thistle this is video of how it works. please help thx

forest lion
#

just fyi

foggy nymph
#

that can be expensive for me in the 3rd world

forest lion
foggy nymph
#

here is the file translated to english

#

by the way i have a problem on my AuctionClient.java file, there is a singleton Passwordmanager that spawn with each client, instead of all clients the same manager, but i dont know how to deal with that. I have tried creating a new socket 9001 between auctionclient.java and chatserver.java, but idk this doesnt work (the server usually shut down)

#

i mean there must be a fundamental issue in the way i coded it

forest lion
#

it needs to be on the server

#

not the client

#

there are N clients, only 1 server

foggy nymph
#

The server never sent any information back to AuctionClient.java file (it was originally named Client.java, but i renamed it to AuctionClient.java bc it was red)

foggy nymph
# forest lion it needs to be on the server

i mean like when i enter password, i need ChatServer.java send information back to AuctionClient.java so that it knows whether to continue or not, but i just dont know how to send it back

#

๐Ÿ†˜

#

@forest lion I have decided to make another socket to connect auction client.java with ChatServer.java, but it make the server always shut down

#

of course it is supposed to be on the server ๐Ÿ˜ญ

forest lion
foggy nymph
#

i meant AuctionClient.java

forest lion
#

so ChatClient.java has an onMessage and you can handle things there

foggy nymph
foggy nymph
forest lion
#

okay so a few things i'm noticing off the bat

#
      final int[] id = {0};
      final int[] check = {0};

this actually won't work like you think it will.

#

good news is that the easy fix is this

#
      final AtomicInteger id = new AtomicInteger(0);
      final AtomicInteger check = new AtomicInteger(0);
#

then instead of id[0] and id[0] = ... use id.get() and id.set(...)

#
      PasswordManagementSystem passwordManagementSystem = PasswordManagementSystem.getInstance();
      GUIIO.println("Please enter your username and password");

      String[] linePass = GUIIO.readln().split("\\s+");
      if (linePass.length < 2) {
        GUIIO.println("Invalid input");
        return;
      }
      String username = linePass[0];
      String password = linePass[1];
      passwordManagementSystem.addUser(username, password);
#

so here the server needs to be managing users, not the client

#

the client takes input but then needs to send a message to the server

#

now to make these communicate:

#

there are more "correct" options and there is an option we can do only if the only thing that needs to be communicated is that you logged in

#

and if you only log in once

#

yeah a lot of stuff you should be doing on the server you are doing in the client

#
          Thread timer = new Thread(() -> {
            try {
              Thread.sleep(120000);
              GUIIO.println(" The auction ended after 120 secs");
              client.sendToServer(new SeeTheList(true));
              GUIIO.println(" You have 20 secs to view the result");
              Thread.sleep(20000);
              System.exit(0);
            } catch (InterruptedException e) {
              e.printStackTrace();
            }
          });
#
import java.util.concurrent.LinkedBlockingQueue;

class Example {
    private final LinkedBlockingQueue<String> out;

    Example(LinkedBlockingQueue<String> out) {
        this.out = out;


    }

    void spin() {
        Thread.startVirtualThread(() -> {
            while (true) {
                try {
                    Thread.sleep(1000);
                    out.add("ping");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
    }
}

public class Queues {

    void main() {

        var q = new LinkedBlockingQueue<String>();
        var example = new Example(q);
        example.spin();

        while (true) {
            var msg = q.poll();
            if (msg != null) {
                IO.println(msg);
            }
        }
    }
}
#

here is your basic example of how to make things on different threads communicate

#

step 1: Make sure the two things (in this case ChatClient and AuctionClient) share the exact same LinkedBlockingQueue

#

step 2: have one thing .add messages to the queue

#

step 3: have the other thing .poll() the queue (or .take() if you want to wait)

#

so in this case when AuctionClient sends a message to the server "new Login(username, password)", you want to then wait on a message from ChatServer saying whether those credentials were correct

#

and obviously you might not want to use Strings

#

you can also make as many queues as you need

#
    private record ConnectedClient<ToClient, ClientState>(
            LinkedBlockingDeque<ToClient> outgoing,
            Thread outgoingThread,
            Thread incomingThread,
            AtomicReference<ClientState> state
    ) {
    }

Just for reference, in the server code I wrote this is how I send messages to the clients. We have one part of the system put the messages to send into a queue

    /// Sends a message to a specific connected client
    protected final boolean sendToClient(ClientId id, ToClient message) {
        var client = clients.get(id);
        if (client == null) {
            LOG.warn("No connected client with id: {}", id);
            return false;
        }

        client.outgoing.add(message);
        return true;
    }

Then another part of the system waiting for messages to come in

                    Thread outgoingThread = Thread.startVirtualThread(() -> {
                        while (true) {
                            if (Thread.interrupted()) {
                                break;
                            }
                            try {
                                try {
                                    var message = q.take();
                                    out.writeObject(message);
                                } catch (InterruptedException e) {
                                    LOG.info("Client connection closed. client_id={}", id);
                                    break;
                                }
                            } catch (Exception e) {
                                LOG.error("Error sending client message", e);
                            }
                        }
                    });
foggy nymph
#

so i will use your example and make AuctionClient and ChatSErver.java communicate?

#

Dont use ChatClient's switch case anymore?

forest lion
#

i'd say more only specific messages you'd forward out of ChatClient

foggy nymph
# forest lion eh - it depends

i think it might be shorter and easier to understand if i can somehow send information from ChatClient.java to AuctionClient.java

forest lion
foggy nymph
forest lion
#

while AuctionClient works imperatively

#

so you'd need to be explicitly checking "do i have a new message? if so..."

foggy nymph
#

so AuctionClient works extremely urgently

forest lion
#

which is a little complicated to get right and you might end up making a new thread regardless

forest lion
#

idk

#

you (probably?) are at a point where you will pass; though idk

#

you are definitely learning more now than you were before

foggy nymph
forest lion
#

yeah thats pretty bad

#

you want that on the server

#

part of what we did here is that we modeled the whole system as "client and server send messages at their leisure"

#

and thats a little annoying for logging in because...well thats a "client sends a message, waits for server response" kind of thing

#

its not the worst though

foggy nymph
forest lion
#

make sure to save your progress as you go

#

in case you break something

foggy nymph
forest lion
#

okay good

foggy nymph
#

@forest lion It's red, what do i do?

forest lion
#

did you just replace check[0] with check?

#

#1502554469592993862 message

foggy nymph
forest lion
#

#1502554469592993862 message

foggy nymph
forest lion
#

That can get tricky as well

foggy nymph
forest lion
#

how do I "explicitly checking "do i have a new message? if so..." "?
I gave you a minimal example above with .poll

foggy nymph
# forest lion so in this case when AuctionClient sends a message to the server "new Login(user...
  1. But AuctionClient can easily send message to ChatServer using client.sendToServer. I only had problem sending stuff the other way around. Do i still use client.sendToServer?
  2. what's AtomicReference<ClientState> state ? What is Reference? What is state?
  3. so the "part of system waiting for messages to come in" is put in a case of switchcase in ChatServer.java ? If it is "wait to come in", then why it is named "outgoingThread" ?
forest lion
#

that isn't code you should write

#

#3 has the same answer

#

i can explain, but its not worth your time right now

foggy nymph
#

apparently, i have a habit of skimming through text due to reading AI's answer (most of its answers are very useless).
yeah and i usually asked AI questions like that.

forest lion
foggy nymph
forest lion
#

okay

#

now for #1 i think the word "client" is what is throwing you

foggy nymph
#

its aswer is clearly unreliable now

forest lion
#

AuctionClient isn't really the "client" to the server

#

its just another part of your program, the one that interacts with the actual client (which is ChatClient)

foggy nymph
#

that's feels off because AuctionClient receives messages from the prompt.

forest lion
#

right but thats not a "client to the server"

#

thats an "interface for your user"

#
User -> Interface -> Client (for the server) <-> Server
#

this is how your program more or less works right now

#

your user can do things with the interface and that part of the program knows how to send info to the client

#

and then the client can send info to and from the server

#

your issue right now is that (other than printlns) it is hard for the client to then communicate to the interface (the part that accepts input, makes a window, etc)

#

and that is what the LinkedBlockingQueue is for

#

User -> Interface <-> Client (for the server) <-> Server

#

filling in that part of the flow

foggy nymph
#

okay i will try to write

foggy nymph
#

@forest lion uhm it's red, i think i did something wrong. Btw the void() method is weird, i cannot easily plug it in.

foggy nymph
forest lion
#

you add an extra argument to the constructor of ChatClient

#

right now it takes two arguments, add a third

#

and when I say "I made you an example" zero times out of 100 am I telling you "copy paste this exactly into your code"

#

I am not making you something to plug in

#

you need to read, understand, and generalize that knowledge

foggy nymph
forest lion
#

then go into ChatClient and add an argument to the constructor

#

ChatClient(String host, int port, <....>) {

}

foggy nymph
forest lion
#

ok

foggy nymph
#

oh i think i realised something

foggy nymph
# forest lion ok

now both have the same LinkedQueue. i never realised that ChatClient is constructed inside AuctionClient

forest lion
foggy nymph
#

@forest lion actually i have not. In AuctionClient i cant do client.spin() and receive the answer

#

idk what i did wrong

#

may be im too sleepy. its 1am and i took sleeping pill 2 hours ago

forest lion
#

The spin method was illustrative

#

it makes zero sense for your program

#

you would want to handle some message in onMessage by pushing to the queue

forest lion
#

that isn't how to make a program

#

it looks like you would want to add to the queue in case LoginValidation

foggy nymph
#

like the amongus semicolon

foggy nymph
forest lion
#

you only use that when sending messages to the server

foggy nymph
foggy nymph
#

@forest lion i think i did something wrong. can u fix?

foggy nymph
#

what should i do now?

forest lion
#

what do you mean?

foggy nymph
forest lion
#

if your goal was to forward a login validation to the queue - yes

foggy nymph
#

May be i put the rest of the code in the while(true) poll statement

#

i have decided to pull all stuff in the while true receive statement. i only receive the confirmation once so may be that can work

#

@forest lion this time the code do run but when i open the 2nd client and type the same username it just do not respond at all anymore

lethal tinselBOT
#

I uploaded your attachments as Gist. This makes them more accessible, for example to mobile users.

forest lion
foggy nymph
lethal tinselBOT
# foggy nymph

I uploaded your attachments as Gist. This makes them more accessible, for example to mobile users.

forest lion
#

you want .take() if you want to wait for a message

foggy nymph
foggy nymph
#

oh it's supposed to be if msg == false

#

i think it works now

#

now i will develop a system that rejects same username

#

now i will do "Lean IDE features"

#

i hope @sick thistle will come back and help me with front end

foggy nymph
#

apparantly it doesnt only need to check whether the password exist or not, but also need to check whether the username exist before

lethal tinselBOT
#

I uploaded your attachments as Gist. This makes them more accessible, for example to mobile users.

foggy nymph
#

@forest lion Um i need help idk why when i type wrong password it is no longer responsive

#

so you sell tutoring service. I'm sorry i cant afford it

#

I'm in a 3rd world country very poor ๐Ÿ™

zealous spire
#

That's strike two since you've been here. No more even hinting of paid help. If you don't want to engage with free help then questions isn't for you. But you're welcome to engage in chit-chat or geek-speak if there's a technical topic you're interested in.

foggy nymph
#

@forest lion In the past, how did you learn JavaFX?

foggy nymph
lethal tinselBOT
#

I uploaded your attachments as Gist. This makes them more accessible, for example to mobile users.

foggy nymph
#

oh no

#

@forest lion
So the system you gave me works absolutely fine when i type correct password when i check

Please enter your username and password
[SYSTEM]: 0 has connected
Please enter your username and password to check
received
CORRECT PASSWORD
This is how to use our service: 
  '/place-bid <id>(Int) <amount>(Int)' in order to bid; 
 use  '/list-item' in order to see the list; 
 use '/create-item  <price>(Int) <name>(String)' if want to create an item 
 '/help' if you want help ```
lethal tinselBOT
foggy nymph
lethal tinselBOT
# foggy nymph

I uploaded your attachments as Gist. This makes them more accessible, for example to mobile users.

foggy nymph
#

OH MY GOD IT WORKS NOW!

#

@forest lion IT WORKS IT WORKS IT WORKS!!!

#

@forest lion turns out there was a GUIIO.println() in PasswordManagementSystem and it's not supposed to be there

#

YAYY!

#

YOU knew i'd figure it out.

#

damn it took me a whole day to figure this out

#

so that's what being a software engineer taste like

#

๐Ÿ˜ญ

foggy nymph
#

@forest lion there is only 1 more bug: if 2nd client type the username and passport of 1st client, he can still login

#

Apparantly to fix this bug the Passwordmanagement system not only need username and password but also ClientId

#

I hope he return from the wood soon

foggy nymph
#

i've fixed it all!

#

@forest lion the app is very good (except front end) now i believe.

foggy nymph
#

@forest lion apparantly, after the auction ended, people can still place bid. idk how to fix this, because i dont know much about threads

foggy nymph
lethal tinselBOT
# foggy nymph

I uploaded your attachments as Gist. This makes them more accessible, for example to mobile users.