implemented automatic reverse connections with GRPL message type
git-svn-id: svn://anubis/gvsu@60 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
137a5f031b
commit
3fdc401fca
@ -181,7 +181,8 @@ public class KaZaGUI extends JFrame
|
|||||||
if (m_server != null)
|
if (m_server != null)
|
||||||
{
|
{
|
||||||
m_server.connectToPeerGroupLeader(
|
m_server.connectToPeerGroupLeader(
|
||||||
m_serverPeerAddressField.getText());
|
m_serverPeerAddressField.getText(),
|
||||||
|
true);
|
||||||
m_serverPeerAddressField.setText("");
|
m_serverPeerAddressField.setText("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,19 +38,34 @@ public class KaZaServer implements Runnable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void connectToPeerGroupLeader(String peerName)
|
public void connectToPeerGroupLeader(String peerName,
|
||||||
|
boolean sendReverseConnectMsg)
|
||||||
{
|
{
|
||||||
|
/* check if the peer group leader is already in our list */
|
||||||
|
synchronized (m_peerGroupLeaders)
|
||||||
|
{
|
||||||
|
for (Socket s : m_peerGroupLeaders)
|
||||||
|
{
|
||||||
|
if (s.getInetAddress().getHostAddress().equals(peerName))
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Socket s;
|
Socket s;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
s = new Socket(peerName, LISTEN_PORT);
|
s = new Socket(peerName, LISTEN_PORT);
|
||||||
DataOutputStream os = new DataOutputStream(s.getOutputStream());
|
DataOutputStream os = new DataOutputStream(s.getOutputStream());
|
||||||
os.writeBytes("HELO KaZaServer\n");
|
os.writeBytes("HELO KaZaServer\n");
|
||||||
|
if (sendReverseConnectMsg)
|
||||||
|
os.writeBytes("GRPL\n");
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* add new peer group leader to the peer group leaders list */
|
||||||
synchronized (m_peerGroupLeaders)
|
synchronized (m_peerGroupLeaders)
|
||||||
{
|
{
|
||||||
m_peerGroupLeaders.add(s);
|
m_peerGroupLeaders.add(s);
|
||||||
@ -193,6 +208,12 @@ public class KaZaServer implements Runnable
|
|||||||
m_socket.close();
|
m_socket.close();
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
|
else if (opCode.equals("GRPL"))
|
||||||
|
{
|
||||||
|
/* user is a peer group leader, initiate a connection
|
||||||
|
* to it if one is not established */
|
||||||
|
connectToPeerGroupLeader(m_clientIP, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) { }
|
catch (Exception e) { }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user