#I need help with building a bidding app
1 messages ยท Page 2 of 1
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
@forest lion I have decided to submit the minecraft command-like app
@forest lion I have decided to ignore Serialization
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
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
I uploaded your attachments as Gist. This makes them more accessible, for example to mobile users.
@sick thistle btw this is my current project
@sick thistle this is video of how it works. please help thx
this is a place to provide help, not to sell help
just fyi
oh so he sells tutoring service
that can be expensive for me in the 3rd world
maybe not
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
? 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.
it needs to be on the server
not the client
there are N clients, only 1 server
i mean, i dont know how to make the server send information back to Auction Client
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)
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 ๐ญ
sendToClient!
you send info with sendToClient!
but it sends to ChatClient.java, not AuctionChat.java
i meant AuctionClient.java
i think i see what is happening
so ChatClient.java has an onMessage and you can handle things there
i mean like if i have another case in ChatClient.java, how do i send information from ChatClient.java to AuctionClient.java?
can you share both files?
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);
}
}
});
so i will use your example and make AuctionClient and ChatSErver.java communicate?
Dont use ChatClient's switch case anymore?
eh - it depends
i'd say more only specific messages you'd forward out of ChatClient
i think it might be shorter and easier to understand if i can somehow send information from ChatClient.java to AuctionClient.java
the problem is that ChatClient works "reactively" - when the server gives it a message it responds
okay, so switch case of ChatClient.java is only to forward to terminal
while AuctionClient works imperatively
so you'd need to be explicitly checking "do i have a new message? if so..."
so AuctionClient works extremely urgently
which is a little complicated to get right and you might end up making a new thread regardless
lets say either forward to terminal or forward again to AuctionClient
idk
you (probably?) are at a point where you will pass; though idk
you are definitely learning more now than you were before
I don't think every client have their own pwd manager is a good idea though
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
i'm sure i will be able to do that, i will "just write", send problem back and u fix both mindset and the code. easy. I still have 9 more days
i push it on github everyday
okay good
The app IntelliJ has Local History feature so no worry
@forest lion It's red, what do i do?
yes, i replaced check[0] with check, because that's also red
read what I wrote
#1502554469592993862 message
okay
OKay so i will add 1 more case in ChatServer.java and make Serversleeps
Maybe do that one after login
That can get tricky as well
so i still create a new thread, but i dont need a new port anymore?
and i will need to be explicitly checking "do i have a new message? if so..."
how do I "explicitly checking "do i have a new message? if so..." "?
you only need ports when two things are communicating over a network
how do I "explicitly checking "do i have a new message? if so..." "?
I gave you a minimal example above with .poll
- 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? - what's
AtomicReference<ClientState> state? What is Reference? What is state? - 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" ?
for #2 its just a demonstration of how i made the library you are using
that isn't code you should write
#3 has the same answer
i can explain, but its not worth your time right now
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.
you asked an AI about what I just wrote?
no, i mean the way i ask AI sounds stupid like that
its aswer is clearly unreliable now
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)
that's feels off because AuctionClient receives messages from the prompt.
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
okay i will try to write
@forest lion uhm it's red, i think i did something wrong. Btw the void() method is weird, i cannot easily plug it in.
uhm i actually dont know how to make both of them share the exact LinkedBlockingQueue. may be make AuctionClient extends ChatClient.java?
no definitely not that
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
but if add an extra argument in the port somewhere it will says expected 3 arguments and idk how to get the 3rd
new ChatClient(<arg1>, <arg2>, <arg3>) when you construct it
then go into ChatClient and add an argument to the constructor
ChatClient(String host, int port, <....>) {
}
in the place in AuctionClient next to port 9009 it demands a linkedqueue for the 3rd parameter
ok
oh i think i realised something
now both have the same LinkedQueue. i never realised that ChatClient is constructed inside AuctionClient
okay now you have a way for ChatClient to send Booleans to AuctionClient
@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
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
maybe, but at some point you need to stop copy pasting things
that isn't how to make a program
it looks like you would want to add to the queue in case LoginValidation
the word spin sounds fun, so i decided to take it.
like the amongus semicolon
so that means use sendToServer
for what?
you only use that when sending messages to the server
for sending from password and username from AuctionClient.java to server, just like efore
i added but i feels very weird
@forest lion i think i did something wrong. can u fix?
get rid of spin
what do you mean?
is my code correct now?
if your goal was to forward a login validation to the queue - yes
uhm how do i deal with this
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
I uploaded your attachments as Gist. This makes them more accessible, for example to mobile users.
poll returns null if no message is there yet
I uploaded your attachments as Gist. This makes them more accessible, for example to mobile users.
you want .take() if you want to wait for a message
now it says WRONG USERNAMe although i typed correct username. I didnt expect this
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
apparantly it doesnt only need to check whether the password exist or not, but also need to check whether the username exist before
I uploaded your attachments as Gist. This makes them more accessible, for example to mobile users.
@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 ๐
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.
@forest lion In the past, how did you learn JavaFX?
idk why on IDE learning the breakpoints work very well it just dont work in my code.
I uploaded your attachments as Gist. This makes them more accessible, for example to mobile users.
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 ```
Detected code, here are some useful tools:
I uploaded your attachments as Gist. This makes them more accessible, for example to mobile users.
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
๐ญ
@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
i've fixed it all!
@forest lion the app is very good (except front end) now i believe.
@forest lion apparantly, after the auction ended, people can still place bid. idk how to fix this, because i dont know much about threads
I uploaded your attachments as Gist. This makes them more accessible, for example to mobile users.