LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-18-2017, 03:36 AM   #1
lagu2653
Member
 
Registered: Jun 2005
Distribution: Lubuntu 16.04 LTS
Posts: 104

Rep: Reputation: 15
Is it impossible to release a socket so you can bind to the same ip:port twice?


Android 6.0 API 23:
I'm using java.net.Socket. I want to release the hostname: port binding so a client phone can: connect, crash so the app has to be restarted on the client phone, then reconnect to the same IP and port without restarting the server app. Is this possible or do I have to start a new server listening on a different port? I'm not using asynchronous communication. What I'm using is more old school.
 
Old 11-22-2017, 04:27 PM   #2
/dev/random
Member
 
Registered: Aug 2012
Location: Ontario, Canada
Distribution: Slackware 14.1, LFS-current, NetBSD 6.1.3
Posts: 272

Rep: Reputation: 103Reputation: 103
What are you trying to achieve?

Even if you were to kill off the socket, reestablishing the same socket on the server end would make the connection very very broken.

so some server @ 192.168.1.10 listens on port 80 (192.168.1.10:80)

so some client @ 192.168.1.20 connects on a ephemeral port (192.168.1.10:10000-65336)

even if you were to break the socket on the server and reestablish the socket, the state of any connection would be in limbo. Because the server might have the right socket, but ultimately were its data is being sent won't be the correct port, so while clients can listen to the servers port 80, they won't be able to reply because in order to reestablish a connection to the server the client would need to open another ephemeral port and because there is no way the server can tell the client to do this your connection hangs in limbo. (until the client make another attempt to contact the server using a different ephemeral port and establishing a connection again.)
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bind a PF_PACKET socket to a specific port number gr1980 Programming 1 10-27-2010 11:57 PM
Raw SCTP socket cannot bind with port? JohnJLewis Linux - Networking 1 07-26-2010 03:14 PM
Can I bind to a serial port using BIND Socket API?? venkat_p257 Linux - General 2 12-04-2007 06:49 AM
How do I get non root access to bind a socket to port 80? APB_4 Linux - Software 2 04-22-2006 11:30 AM
Why is my socket unable to bind to the port in the C Code. mcp_achindra Programming 10 03-24-2004 09:34 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration