Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Threads and Socket client.

  1. #1
    Junior Member
    Join Date
    Aug 2019
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Threads and Socket client.

    Hi guys, I've been programming in java for some time, but I'm not very advanced, I have to make a socket application, client side only.
    This application receives data, searches the database, and returns a value to the server, is working, there is no delay in response, all ok, but the problem is that I can not know when the connection to the server was broken, and the server sends the right question, doesn't answer any kind of command, so I can't make a keepAlive, so I decided to create a timer to restart all clients in 5 minutes, but I noticed that some clients don't stop in time, starting 2 clients on the same server, and with that I get a block on the server, would anyone have any other idea to perform this process?
    For you to understand, my scenario is as follows:
    8 turnstiles running as a server (no option to run as a client)
    1 server, running my application, starting 8 clients, running in threads

    This is the code where I start clients, which get ips from the database turnstiles, using the same port

    Thank you...
    Last edited by semperfy; September 5th, 2019 at 08:06 AM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Threads and Socket client.

    I don't understand what these are: 8 turnstiles Can you explain?
    And what does running as a server mean?

    Do you have any output that shows what you are talking about?

    when the connection to the server was broken
    The Sockets should throw an exception.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    semperfy (August 28th, 2019)

  4. #3
    Junior Member
    Join Date
    Aug 2019
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Threads and Socket client.

    hey Norm, sorry, my english is very bad, im from Brazil, the turnstiles are access turnstiles, or call ratchet, they work with socket connection, but, they running in server mode, and read rfid card, when they read the card, if have a "agent" in client mode connected to then,they send a array bytes, containing card chip number, and the "agent", after checking, responds to her whether or not she releases/open.
    The "agent" is my application, when the connection drops, switch or power outage, that doesn't affect my application, the server (turnstiles), keep looking for the agent, and the agent does not identify this fall, does not enter a throw exception, just keep waiting.
    My solution was to restart the connection every five minutes, regardless of whether or not the connection, but, as there are 8 agents, when calling the method that stops the thread and the connection, not all stop, some threads keep running, and start a new.
    The output, after converted, is something like this: s01+RR+000]00000000000171012132]11/07/2019 17:20:31]1]0}000
    what is bold is the number of the card chip that I check whether or not it can pass there.
    I hope I have clarified better, once again, sorry for my English, thanks for the help.
    postJava.jpg

Similar Threads

  1. Socket Threads
    By jtseaman85 in forum Threads
    Replies: 2
    Last Post: September 15th, 2011, 12:24 AM
  2. Socket java client
    By atef201080 in forum Java Networking
    Replies: 4
    Last Post: July 13th, 2011, 08:35 AM
  3. Threads in multi client-server application
    By KingOfClubs in forum Threads
    Replies: 1
    Last Post: June 11th, 2011, 12:10 AM
  4. Need help with client socket
    By Robtn in forum Java Theory & Questions
    Replies: 2
    Last Post: May 23rd, 2011, 02:26 PM
  5. client/server socket
    By Java_dude_101 in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: January 18th, 2011, 01:16 AM