# Java Socket Server

**URL:** <https://forum.kirupa.com/t/java-socket-server/185776>\
**Category:** programming\
**Created:** [April 16, 2006, 12:41pm UTC](https://forum.kirupa.com/t/java-socket-server/185776 "2006-04-16T12:41:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mathew\_er](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@mathew\_er](https://forum.kirupa.com/u/mathew_er)\
**Post date:** [April 16, 2006, 12:41pm UTC](https://forum.kirupa.com/t/java-socket-server/185776/1 "2006-04-16T12:41:41Z")

</div>

Hi,  
I now find myself in need of a socket server made with Java.

Just to let you know what I need to do… Im creating a multi-agent simulation in Java and I want a Flash client to be able to view the progress of the simulation. Flash is going to recieve only information about agents (position and other properties) and probbably send some information (some additional agent info requests).

I have _[this](http://www.gotoandplay.it/_articles/2003/12/xmlSocket.php)_ example. Its supersimple server. I have no idea how to continue. If I close the running .swf file, it ends the server app. I need it to keep running. My idea how it could work is to: Listen for connections, handle incoming connections (pass them to some manager to keep track of them) and add some functionality to react on clients requests and broadcast messages.

Im not too well familiar with Java and sometimes its just giving me headaches.

Do you have an ideas, pointer where and how to continue?

btw. I have noticed that it sends message from server only when it recieves one. Does it allways have to be like that?

---

<div class="post-metadata">

**Author:** ![mathew\_er](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@mathew\_er](https://forum.kirupa.com/u/mathew_er)\
**Post date:** [April 16, 2006, 7:10pm UTC](https://forum.kirupa.com/t/java-socket-server/185776/2 "2006-04-16T19:10:11Z")

</div>

Nevermind, problem almost solved… I was lucky enough to find an appropriate example, which gave me good starting point. =)

---

<div class="post-metadata">

**Author:** ![Jeff\_Wheeler](https://avatars.discourse-cdn.com/v4/letter/j/59ef9b/32.png) [@Jeff\_Wheeler](https://forum.kirupa.com/u/Jeff_Wheeler)\
**Post date:** [April 16, 2006, 7:14pm UTC](https://forum.kirupa.com/t/java-socket-server/185776/3 "2006-04-16T19:14:08Z")

</div>

Can you share your solution for the future?

---

<div class="post-metadata">

**Author:** ![mathew\_er](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@mathew\_er](https://forum.kirupa.com/u/mathew_er)\
**Post date:** [April 16, 2006, 9:49pm UTC](https://forum.kirupa.com/t/java-socket-server/185776/4 "2006-04-16T21:49:14Z")

</div>

Sure 🙂  
It just needs a tiny bit more of work to post how I modified it… Ill edit this post with source later tonight

… anyways here is the article where I got the code from ([link](http://www.wutka.com/hackingjava/ch37.htm))

---

<div class="post-metadata">

**Author:** ![Jeff\_Wheeler](https://avatars.discourse-cdn.com/v4/letter/j/59ef9b/32.png) [@Jeff\_Wheeler](https://forum.kirupa.com/u/Jeff_Wheeler)\
**Post date:** [April 16, 2006, 9:55pm UTC](https://forum.kirupa.com/t/java-socket-server/185776/5 "2006-04-16T21:55:49Z")

</div>

That’s sweet… I can’t wait to play with stuff like that (on the new servers we can use at school).

---

<div class="post-metadata">

**Author:** ![mathew\_er](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@mathew\_er](https://forum.kirupa.com/u/mathew_er)\
**Post date:** [April 16, 2006, 10:35pm UTC](https://forum.kirupa.com/t/java-socket-server/185776/6 "2006-04-16T22:35:55Z")

</div>

:lol: for now Im testing it at localhost… its fun to see just two windows talk to each other

Ya, servers… thats gonna be problem ☹  
As I looked at my hosting, it doesnt even seem to offer JSP support and I will need a stand-alone Java app to run there… I might ask someone at school, but Im leaving it in about a month (if Im not gonna stay there as a teacher) and they are not going to be willing to keep it running. Do you know of any place I could use for this purpose?

---

<div class="post-metadata">

**Author:** ![Jeff\_Wheeler](https://avatars.discourse-cdn.com/v4/letter/j/59ef9b/32.png) [@Jeff\_Wheeler](https://forum.kirupa.com/u/Jeff_Wheeler)\
**Post date:** [April 16, 2006, 11:04pm UTC](https://forum.kirupa.com/t/java-socket-server/185776/7 "2006-04-16T23:04:38Z")

</div>

Google Java hosting :whistle:

---

<div class="post-metadata">

**Author:** ![mathew\_er](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@mathew\_er](https://forum.kirupa.com/u/mathew_er)\
**Post date:** [April 17, 2006, 12:04am UTC](https://forum.kirupa.com/t/java-socket-server/185776/8 "2006-04-17T00:04:48Z")

</div>

No need to do so anymore… I just made a deal with a guy who is setting up his own server. Everything just works perfectly today… I should go out for a date :lol:

I have attached what I have done so far on the initial subject. Its modification of both mentioned examples. I rather simplified it so it can be more understandable for anybody who is new to Java as I am 😉

What does it do? Create a socket server, Manage connections, send/recieve messages between client and server and also it can broadcast a message to everyone.
