Results 1 to 9 of 9

Thread: java and flash

  1. #1
    danmc977 is offline Member
    Join Date
    Apr 2011
    Posts
    5
    Rep Power
    0

    Default java and flash

    Hi guys, first post, be nice :)

    Was just wondering if anyone could tell me how to change the following java server into a multi-threaded one, it has threading capabilities already I believe, so im sure theres something im missing but my java isnt that good:

    gruchalski.com » Archive » XMLSocket.send / Socket.writeUTFBytes doesn’t work?

    Thanks
    Dan

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,993
    Rep Power
    9

    Default

    That's not really how this works. Not many people are going to click on external links, and even fewer people are going to wade through a whole program worth of code.

    We can answer specific questions about specific code (in SSCCE form), but general questions like this aren't really answerable.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    danmc977 is offline Member
    Join Date
    Apr 2011
    Posts
    5
    Rep Power
    0

    Default

    @KevinWorkman Thanks for the reply, I understand that someone isnt going to wade through a big program and basically do my work for me, I think you misunderstood my request, I was hoping someone could help me with multithreading;
    The link I gave is the only working server I have found that correctly serves a policy file to a flash client, but currently it doesnt allow multiple connections from clients.

    So I was wondering if someone could help me out with multithreading, in regards to the link I have posted.

    But anyway thanks for the reply

    Dan

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,993
    Rep Power
    9

    Default

    If I were you, I'd start by reading through this and trying out some simple examples: Lesson: Concurrency (The Java™ Tutorials > Essential Classes)
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    danmc977 is offline Member
    Join Date
    Apr 2011
    Posts
    5
    Rep Power
    0

    Default

    @KevinWorkman again thanks for the reply, ive read through the link you posted, and believe me when I say ive read through quite a few tutorials etc when trying to sort this out, but no matter what I read or try I can't get it to work.
    The link I posted already includes threading capabilities, but i just can't work out how to get it to work, really would appreciate any help here.

    Thanks
    Dan

  6. #6
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    The server is already multi-threaded and already accepts multiple clients at a time. Have you tried using it? If so, what issue are you having?

  7. #7
    danmc977 is offline Member
    Join Date
    Apr 2011
    Posts
    5
    Rep Power
    0

    Default

    Thanks for the reply @toadaly

    The server accepts a connection from one client, and can receive and send data from this client, but if another client connects, the server will only send data received to the sending client, not all clients.

    I want the server to receive data from any client and then output it to all clients.

    Really appreciate your help

    Thanks
    Dan

  8. #8
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    Ok. What you need to do then, is create a Set of Socket's. Each time a new client Socket is created, add it to the set. Then create a java.util.BlockingQueue (I'd probably use a simple ArrayBlockingQueue), and a service thread. The service thread will block on queue.take().

    When one of the client handler threads receives data, you will call queue.put() with whatever message you're wanting to send to the clients. This will cause the service queue to kick into action. In the service queue, you will loop through the Set of Sockets calling 'getOutputStream' and writing to the output stream. Flush after each write, but do not close the stream.

    You must handle exceptions carefully. If the write command throws an exception, then you want to close that socket down (which should cause the associated client thread to throw an exception - which you must handle and return from the thread), and also remove that Socket from the Set.

    Good luck!

  9. #9
    danmc977 is offline Member
    Join Date
    Apr 2011
    Posts
    5
    Rep Power
    0

Similar Threads

  1. Java add flash object
    By Dennis in forum Advanced Java
    Replies: 0
    Last Post: 01-06-2011, 09:06 PM
  2. Integrating java and flash
    By ak88 in forum New To Java
    Replies: 1
    Last Post: 01-18-2010, 04:41 PM
  3. Java Server, Flash Client
    By matbuckland in forum New To Java
    Replies: 3
    Last Post: 09-01-2009, 10:58 AM
  4. Flash application in Java
    By SrihariCh in forum New To Java
    Replies: 0
    Last Post: 03-31-2009, 01:23 PM
  5. JAVA, Ajax, Flash
    By Digital Dispatching in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 02-06-2008, 08:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •