kandi X-RAY | SocketProgramming Summary
kandi X-RAY | SocketProgramming Summary
SocketProgramming
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Start the server
- Creates a new socket channel
- Start a new socket channel
- Encodes a message
SocketProgramming Key Features
SocketProgramming Examples and Code Snippets
Community Discussions
Trending Discussions on SocketProgramming
QUESTION
I'm trying to implement a really simple echo-back multi-threaded server.
I used the thread pool created with newFixedThreadPool
, but it looks like the number of concurrent connections is fixed at nThreads
(passed into newFixedThreadPool
). For example, if I set nThreads
to 3, then the fourth client that connects cannot interact with the server.
This is rather weird because the documentation says "Creates a thread pool that reuses a fixed number of threads operating off a shared unbounded queue."
Since the documentation also says that "If additional tasks are submitted when all threads are active, they will wait in the queue until a thread is available." I suspect my threads are never "released" so that they never became available for reuse.
I think this could be a silly mistake, but I couldn't figure out what's wrong. Here's my client handler's run()
method, which I think is very similar to the code found here (client
below is just a Socket
connected to the client):
ANSWER
Answered 2017-Sep-27 at 07:03I don't have an answer to why the forth connection is hanging, other than to say here is a version of the code which does work...
QUESTION
My understanding about socket programming mainly stems from this tutorial:
CS 50 Software Design and Implementation, Lecture 19, Socket Programming
Given a TCP client/server model where the client and server are running in two different systems and a proxy is in between them, assume the client is able to send messages to the server through the proxy, then the server suddenly becomes non-responsive (say it got reset). What happens to the connection between the proxy and server, and how to handle this?
I mean, what technique can I employ to detect such an event, close my connection, and return an error message to the client?
One way I can think of is to check the receive buffer in the proxy, and if there is no data in it for some time, tell the client that the server is down. But I think that timeout is a primitive approach. Are there any known standard methods or alternatives available in socket programming for this?
...ANSWER
Answered 2017-Sep-15 at 01:28Given a TCP client/server model where the client and server are running in two different systems and a proxy is in between them, assume the client is able to send messages to the server through the proxy, then the server suddenly becomes non-responsive (say it got reset). What happens to the connection between the proxy and server
Either:
- Nothing.
- A read timeout, or
- a 'connection reset' error
depending entirely on what the proxy is doing. If it's receiving, (2), or (3) if there was already a pending send. If it's sending, (3), but not on the first send, because of buffering. Eventually a send will cause (3).
and how to handle this?
Close the connection, and the connection to the client. If it was a reset, you might want to propagate that to the client via a technique I will not document here as it is so widely misused. If it was a read timeout, you might even want to try to propagate that to the client by simply doing nothing for five minutes or whatever is appropriate, and then closing or resetting the connection.
I mean, what technique can I employ to detect such an event, close my connection, and return an error message to the client?
See above.
One way I can think of is to check the receive buffer in the proxy, and if there is no data in it for some time, tell the client that the server is down. But I think that timeout is a primitive approach.
It isn't.
Are there any known standard methods or alternatives available in socket programming for this?
See above.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install SocketProgramming
You can use SocketProgramming like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the SocketProgramming component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page