Class Connection
java.lang.Object
org.eclipse.emf.mwe.internal.core.debug.communication.Connection
This class implements a socket connection model. "Packages" (units of information) can be transfered between two
different virtual machines. During the initialisation of a socket connection a reader and a writer thread are
established. This class can be used both on the sender and receiver side.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
accept
(int timeout) the server listens for a client to connect, creates new reader and writer threads and sends a first handshake packet to test the communicationvoid
close()
close and dispose the socket and the (possibly waiting) sender threadvoid
connect
(int port) the client establishes the connection here, creates new reader and writer threads and waits for a handshake packet to be received from the serverboolean
listenForPackage
(Class<? extends AbstractPackage> type) listenForPackage
(Class<? extends AbstractPackage> type, int refId) protected AbstractPackage
int
sendPackage
(AbstractPackage packet) void
startListeningSocket
(int port) create a newServerSocket
.protected void
writePackage
(AbstractPackage packet)
-
Constructor Details
-
Connection
public Connection()
-
-
Method Details
-
listenForPackage
public AbstractPackage listenForPackage(Class<? extends AbstractPackage> type) throws InterruptedIOException - Throws:
InterruptedIOException
-
listenForPackage
public AbstractPackage listenForPackage(Class<? extends AbstractPackage> type, int refId) throws InterruptedIOException - Throws:
InterruptedIOException
-
sendPackage
- Throws:
IOException
-
startListeningSocket
create a newServerSocket
.- Parameters:
port
- the communication port- Throws:
IOException
-
accept
the server listens for a client to connect, creates new reader and writer threads and sends a first handshake packet to test the communication- Parameters:
timeout
-- Throws:
IOException
-
connect
the client establishes the connection here, creates new reader and writer threads and waits for a handshake packet to be received from the server- Parameters:
port
-- Throws:
IOException
-
isConnected
public boolean isConnected()- Returns:
- if the socket connection is still active
-
close
public void close()close and dispose the socket and the (possibly waiting) sender thread -
readPackage
- Throws:
IOException
-
writePackage
- Throws:
IOException
-