Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Android how do I disconnect a socket?

So I've got a socket that is connected to an outside web address and when it gets a certain message it's supposed to disconnect. I tried calling socket.close() but socket.isConnected() is still true. No luck searching for an answer

like image 488
user2312638 Avatar asked Aug 23 '13 15:08

user2312638


People also ask

How do you break a socket connection?

To terminate the accept() ed connection close the accepted socket (what you call connected) by optionally first using shutdown() followed by close () . To then accept a new connection loop right back before the call to accept() , do not go via bind() and listen() again.

What is socket connection Android?

Socket programming is a method of communicating between two devices connected to the same network. Two sockets, one on the client and one on the server, interact. An IP address plus a port make up a socket's address. Over the specified port, the server application begins to listen to clients.

What is socket programming in Android Studio?

Socket programming is a way for devices to communicate over a network. Two sockets communicate, one on the client-side and one on the server-side. A socket's address consists of an IP and a port. The server application starts to listen to clients over the defined port.


1 Answers

isConnected() only tells you if you made a successful connection to a socket. isClosed() tells you if you called close().

Check out this guys response https://stackoverflow.com/a/3701249/2453771

like image 116
Nick Avatar answered Sep 20 '22 04:09

Nick