Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+14 votes

I am currently trying to create a chatroom so that I can chat through two different instances of the same program using sockets in java. How can you determine one as a client and one as a host in order to connect the two, or is this not necessary? What is the best way to connect these instances?

asked in CSC 305 Fall 2024 by (1.8k points)

1 Answer

+5 votes

My suggested route is to use the Python server program that's in the ChatterBox repo, or perhaps a lightly modified version of it.

Then any number of Java programs can connect to it as clients, as long as they use different usernames when they connect to it.

In terms of hosting the server on Google Cloud,
have you tried the Quick and Dirty server setup guide I sent out to everyone on the power outage day?

answered by (5.7k points)
+3

Not yet, I will try that. Thank you!

+3

I have been trying to add the python file from ChatterBox to my project so I can use the code. I have been doing some googling to try and set up python within the project which has shown to be unsuccessful. I have python in my project, but it seems the import statements do not work. I get the following errors from the import statements with the code right now:

Traceback (most recent call last):
File "/Users/ianpalmroos/git/DowitcherRepo/DowitcherProject/chatServer/main.py", line 10, in

from fastapi import FastAPI, WebSocket

ModuleNotFoundError: No module named 'fastapi'

...