Aldut Java Chat Rooms
💣 👉🏻👉🏻👉🏻 ALL INFORMATION CLICK HERE 👈🏻👈🏻👈🏻
Aldut Java Chat Rooms
Sign up with email
Sign up
Sign up with Google
Sign up with GitHub
Sign up with Facebook
Asked
7 years, 1 month ago
Active
2 years, 4 months ago
46.4k 25 25 gold badges 187 187 silver badges 173 173 bronze badges
285 3 3 gold badges 8 8 silver badges 19 19 bronze badges
please post the errors you got. Also, from what i see, you call runOutput() once, and there is no loop, meaning s = ss.accept() is only gonna be called once
– Dioxin
Dec 27 '13 at 21:23
Look at my edited answer. Hope that helps you a bit
– Dioxin
Dec 28 '13 at 3:34
12.7k 5 5 gold badges 33 33 silver badges 69 69 bronze badges
that really hepled in accepting many clients,but still things clients write don't reach the server :\
– user3100088
Dec 27 '13 at 21:34
thanks alot bro , but still that didn't work out(no errors though)
– user3100088
Dec 27 '13 at 21:47
@VinceEmigh When using your server class, I get the error 'running cannot be resolved to a variable'. Do you know why this happens?
– Sam
Oct 8 '18 at 4:21
@Jacob You need to declare a running variable. I have edited my answer , although this is an old answer which expresses horrid design, so I wouldn't recommend emulating it.
– Dioxin
Oct 8 '18 at 4:28
729 7 7 silver badges 22 22 bronze badges
Stack Overflow
Questions
Jobs
Developer Jobs Directory
Salary Calculator
Help
Mobile
Disable Responsiveness
Products
Teams
Talent
Advertising
Enterprise
Company
About
Press
Work Here
Legal
Privacy Policy
Terms of Service
Contact Us
Stack Exchange Network
Technology
Life / Arts
Culture / Recreation
Science
Other
Join Stack Overflow to learn, share knowledge, and build your career.
I was making a chat room project where the server accepts many clients, and whatever the client writes reaches the other clients and so on.
Unfortunately the server accepts maximum 2 clients and after one client writes an input it gives errors.
Your 'n' thread has no loop, meaning its gonna run once (accept a connection), then die off.
Dont worry, your thread will be paused at 'ss.accept()', since it will wait until a socket is accepted to continue.
Sorry, wrote that really quick, dont have much time. Ill come back and relate it to your code in a bit if it doesnt help.
You need some way of continuously retrieving input from the Server's input stream, in which you can then handle the input.
That loop loops each time you retrieve something from inputstream.readUTF() (and isnt null, of course). Hopefully that example will help you
After actually reading your code and testing it, i have noticed that your structure seems a bit off. First, your Thread n in your server is responsible for accepting connections ( addClient() ), but you also call it first thing in your Thread input ?
Thread n is handling accepting connections, so with the loop, Thread n is fine.
Thread input is handling input retrieved from clients. This is where you are getting confused.
Each client should have their own InputStream and OutputStream server-sided. Similar to how you have a list for Sockets (since you are gonna be creating multiple Sockets server-sided), you need multiple Streams aswell. For this, I suggest making a User class, then if anything, have your ArrayList for User, not Socket.
in.readLine() is depreciated, which means it's out-dated and shouldn't be used (to avoid bugs).
Now that you have your User class set up, which handles the data, you can now create a new User each time a connection is received.
Hopefully, that'll give you a better idea for how your server should run.
As for your client.. Well, there are a ton of things you should realize:
First, big problem, you're re-initializing your DataOutputStream each loop, which is gonna cause the stream server-side to close. Gotta take it out of the loop, possibly put it before (or look at my server example for a better idea of handling stream initialization).
Second, the names should be kept on the Server, rather than the Client. This way, its easy to iterate through the names, check if its taken, ect..
Third, nothing with networking, but seeing how you never refer to Thread n or Thread input , other than to start it, you should remove the reference variable. (even though im pretty sure local vars are picked up by the Garbage Collector, still looks nicer). Example:
Hope this helps you understand how a multi-threaded server works! :)
PS: This is a very basic server, and really shouldn't be used for large scale applications.
Creating new threads (new User()) can cause a lot of overhead, so its best to handle connections using an ExecutorService, or some other type of threadpool service. Good luck!
I think you should rethink the logic of a lot of the server code. You should have one thread that handles connecting clients, and assigns them their own input threads. You can then have a method on that input reading thread that will iterate through the clients sending them the message.
When I first started writing my Client-Server chat program I found this little Oracle doc very useful. Hopefully it will help you too.
You should note this part of the document in particular:
Client connection requests are queued at the port, so the server must accept the connections sequentially. However, the server can service them simultaneously through the use of threads—one thread per each client connection.
The basic flow of logic in such a server is this:
while (true) {
accept a connection;
create a thread to deal with the client;
}
By clicking “Post Your Answer”, you agree to our terms of service , privacy policy and cookie policy
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa . rev 2021.2.12.38571
GitHub - lhrotk/ Java - Chat - Room : A simple java chat room project with UI
Server client chat room in Java - Stack Overflow
Чат на Java (Серверная часть)
Multi Chat Rooms using Java - YouTube
How to Create a Chat Console Application in Java using Socket
Опубликовано Март 9, 2017
от Алексей Гулынин
4 комментарии
Какие темы вам более всего интересны?
Какие темы вам более всего интересны?
HTML, HTML5
CSS, CSS3
JavaScript, JQuery
PHP
C#
VBA
Всем доброго времени суток. На связи Алексей Гулынин. В данной статье я бы хотел написать серверную часть простого чата на Java . Все комментарии будут даны в коде.
Скачать уже готовый проект полностью можно по ссылке .
Проект серверной части будет состоять из 3 файлов:
В классе Main будет просто создаваться экземпляр нашего сервера:
В данной статье мы создали серверную часть простого чата на Java .
На связи был Алексей Гулынин, оставляйте свои комментарии, увидимся в следующих статьях.
Уже 2457 дней , как я веду свой блог.
Heather Brooke Porn Bio
Wife Gangbangs
Asian Girl Eat Cum
Lesbians Eat Pussy Pics
Real Amature Pussy
![](http://fooobar.com/img/6ea44629824880b265439055ef897370.jpg)
![](http://image.winudf.com/v2/image/Y29tLkNvZGVjdHVyZS5UYWxrR2F0b3Jfc2NyZWVuXzVfYjZhcHVkcXY/screen-5.jpg?fakeurl=1&type=.jpg)
![](http://maniacslounge.com/images/chatroom.jpg)
![](http://www.warcraftmovies.com/images/java_chat.jpg)
![](http://cdn-image.hipwee.com/wp-content/uploads/2016/11/hipwee-INILAH-ALASAN-SITUS-VIDEO-CHAT-CAMFROG-DIBLOKIR-DI-INDONESIA.jpg)
![](http://2.bp.blogspot.com/-6IteaX07u9w/T9SxgJa_ARI/AAAAAAAAJQY/Y8JgpDCpMI8/s1600/untitled.jpg)
![](http://adventuresintiki.com/img/a5c7ab93a89b931fc39c51f76be12679.jpg)
![](http://is1-ssl.mzstatic.com/image/thumb/Purple113/v4/11/9d/95/119d95ea-f1ba-a21d-b4ac-21e39cb226d5/pr_source.jpg/392x696bb.jpg)
![](http://dedm.pnpi.spb.ru/chat/imgs/javachatxp_with_mail.gif)
![](http://mayukhbose.com/images/java_1.2.gif)
![](http://dlcache.com/images/9b0/chat-forum.com.gif)
![](http://2.bp.blogspot.com/-kZ2c1gsm5mU/UF9A150ahZI/AAAAAAAAAEU/fsj9lWaEeIM/s1600/ChatSnap.png)
![](http://spyurk.am/uploads/images/44be87ad89d94c12d3bf.png)
![](http://www.hascode.com/wp-content/uploads/2014/11/javafx-chat-client.png)
![](http://raw.githubusercontent.com/Drakirus/java-chat/master/screen.png)
![](http://2.bp.blogspot.com/-2fZ_pKK67vs/Uab_9Y2HlEI/AAAAAAAAAcc/Jg4AdT4dnxY/s1600/chat1.png)
![](http://mirsofta.ru/screen/36752256_1.jpg)
![](http://i.ytimg.com/vi/fuFCAhcptiY/maxresdefault.jpg)
![](http://img-winapps.lisisoft.com/img/6/0/906-1-chat-room-424cdcc99ebe.jpg)
![](http://2.bp.blogspot.com/-KURnr_upimA/T7zvWoQtuoI/AAAAAAAABWE/gJ4LYfQxAak/s1600/Camfrog%20Video%20Chat.jpg)
![](http://www.pakidreamz.net/wp-content/uploads/2016/10/cam-chat-room.jpg)
![](http://image.winudf.com/v2/image/bGl0ZS5jaGF0Nzg2LmNvbV9zY3JlZW5zaG90c180X2JjMzIwNGU5/screen-4.jpg?fakeurl=1&type=.jpg)
![](http://images.pcworld.com/news/graphics/152147-camfrog_original.jpg)
![](http://image.winudf.com/v2/image/Y29tLmNoYXQucm9vbXMubGl2ZS5kYXRpbmcuYW5vbnltb3VzX3NjcmVlbl82X2xreGUzeHJu/screen-6.jpg?fakeurl=1&type=.jpg)
![](http://i.pinimg.com/originals/67/4d/c8/674dc837a1173f7726d50611d1f6356a.jpg)
![](http://i.ytimg.com/vi/b-gbBTYg0cA/maxresdefault.jpg)
![](http://image.winudf.com/v2/image/Y29tLmdvc3N5LmNoYXRfc2NyZWVuXzFfMTUyMjUyMTU3OF8wMjE/screen-1.jpg?fakeurl=1&type=.jpg)
![](http://img.biblprog.com/programsimages/camfrog/Camfrog.jpg)
![](http://image.winudf.com/v2/image1/b25saW5lNGNoYXQuY29tX3NjcmVlbl8zXzE1NjcwNjk3MjFfMDUy/screen-3.jpg?fakeurl=1&type=.jpg)
![](http://image.pngline.com/1474/14743139/game-of-thrones-season-5-online-sa-prevodom.png)
![](http://steamunpowered.eu/wp-content/uploads/2014/10/Origin-voice-chat-3.png)
![](http://cofenac.org/img/online-free-sex-chat-rooms.png)
![](http://videochats.ru/images/chatrandom.png)
![](http://i.stack.imgur.com/JrDrf.jpg)
![](http://is4-ssl.mzstatic.com/image/thumb/Purple123/v4/5b/8d/04/5b8d04e7-0009-dca3-6e5e-16300ed71461/pr_source.jpg/392x696bb.jpg)
![](http://elgg.org/plugins/574235/icons/883297.jpg)
![](http://quirkypony.files.wordpress.com/2013/05/aol-chat-directory-anatomy.jpg)
![](http://step-trader.com/wp-content/uploads/2015/07/Chat-Room-13-07-15.jpg)
![](http://image.winudf.com/v2/image1/Y29tLm1lc3Nlbmdlci5mdW5jaGF0X3NjcmVlbl83XzE1NTk3OTk0NjlfMDc4/screen-7.jpg?fakeurl=1&type=.jpg)
![](http://xplayon.com/images/softimages0/16-10/Anonimnyy-chat-na-russkom/Anonimnyy-chat-na-russkom-2.jpg)
![](http://www.tradingreviewers.com/wp-content/uploads/2020/04/investors-underground-chat-room.jpg)
![](http://miro.medium.com/max/765/0*eTtGk2nn4oDPXmBI.jpg)
![](http://i.imgur.com/H55MfMY.jpg)
![](http://digital-locker.design.yorku.ca/4003af14/syong/img/apps/chatroulette_pc01.jpg)
![](http://www.fileguru.com/images/b/morevil_web_chat_network_and_internet_chat_tools-1709.gif)
![](http://transitionwatch.org/img/319941.gif)
![](http://installatron.com/images/remote/ss1_phpfreechat.gif)
![](http://4.bp.blogspot.com/-pAAn0R5csc4/UZtZA1_ks9I/AAAAAAAABVE/FCTmmEI_D5o/s1600/usa+free+online-chat-rooms.png)
![](http://ca346f11304.files.wordpress.com/2011/10/shot1.png)
![](http://jbochi.com/gifs/main2_03_09_00.png)
![](http://a5.mzstatic.com/us/r30/Purple71/v4/2f/79/3b/2f793ba2-407a-f808-7bb3-cce933ebfd88/sc1024x768.jpeg)