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)
|
||||
{
|
||||
m_server.connectToPeerGroupLeader(
|
||||
m_serverPeerAddressField.getText());
|
||||
m_serverPeerAddressField.getText(),
|
||||
true);
|
||||
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;
|
||||
try
|
||||
{
|
||||
s = new Socket(peerName, LISTEN_PORT);
|
||||
DataOutputStream os = new DataOutputStream(s.getOutputStream());
|
||||
os.writeBytes("HELO KaZaServer\n");
|
||||
if (sendReverseConnectMsg)
|
||||
os.writeBytes("GRPL\n");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* add new peer group leader to the peer group leaders list */
|
||||
synchronized (m_peerGroupLeaders)
|
||||
{
|
||||
m_peerGroupLeaders.add(s);
|
||||
@ -193,6 +208,12 @@ public class KaZaServer implements Runnable
|
||||
m_socket.close();
|
||||
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) { }
|
||||
|
Loading…
x
Reference in New Issue
Block a user