Hey,
I have a JAVA app that loads my social networking website, and what I am trying to achieve is using a JAVA applet built into the website with a "Start Party" button, then when the party has started the applet will display an "invite Friends" button, then when the friend accept's the invite, it starts a voice chat client on their end and connects to the Party owners Server... but me being a novice at JAVA needs some help , if you can point me to some tutorials (Preferably Video Tuts), that would be much appreciated, thankyou
I have been trying myself and I have the following code for the server, but when I try to load it on app start, it hangs, any hints ...
Code:
import java.net.*;
import java.io.*;
import java.util.*;
public static void start_voip_server() throws IOException, Exception {
ServerSocket serverSocket = new ServerSocket(3000);
while(true){Thread echoThread = new Thread(new EchoThread(serverSocket.accept()));
echoThread.start();}
}
public static void main(String[] args) throws Exception {
start_voip_server();
// SOME MORE CODE THAT WON'T LOAD DUE TO VOIP SERVER HANG...
}
class EchoThread implements Runnable
{
public static Collection<Socket> sockets = new ArrayList<Socket>();
Socket connection = null;
DataInputStream dataIn = null;
DataOutputStream dataOut = null;
public EchoThread(Socket conn) throws Exception
{
connection = conn;
dataIn = new DataInputStream(connection.getInputStream());
dataOut = new DataOutputStream(connection.getOutputStream());
sockets.add(connection);
}
public void run()
{
int bytesRead = 0;
byte[] inBytes = new byte[1];
while(bytesRead != -1)
{
try{bytesRead = dataIn.read(inBytes, 0, inBytes.length);}catch (IOException e){}
if(bytesRead >= 0)
{
sendToAll(inBytes, bytesRead);
}
}
sockets.remove(connection);
}
public static void sendToAll(byte[] byteArray, int q)
{
Iterator<Socket> sockIt = sockets.iterator();
while(sockIt.hasNext())
{
Socket temp = sockIt.next();
DataOutputStream tempOut = null;
try
{
tempOut = new DataOutputStream(temp.getOutputStream());
} catch (IOException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
try{tempOut.write(byteArray, 0, q);}catch (IOException e){}
}
}
}
Bookmarks