I'm currently working on a kind of chat program based on this tutorial:
http://www.dreaminco...wtopic38672.htm
Well, i got this now as my server:
import java.net.ServerSocket;
import java.net.Socket;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.lang.*;
public class ServerTest
{
public ServerSocket serverSocket;
public Socket clientSocket;
public BufferedReader bufferedReader;
public String inputLine;
public static void main(String[] args)
{
ServerTest test = new ServerTest();
}
public ServerTest()
{
// Wachten op de client om te connecten met poort 10005
try
{
serverSocket = new ServerSocket(10005);
clientSocket = serverSocket.accept();
// Maakt een reader
bufferedReader = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
// Ontvangen bericht client
while((inputLine = bufferedReader.readLine()) != null)
System.out.println(inputLine);
}
catch(IOException e)
{
System.out.println(e);
}
}
}
And this as my client:
import java.net.Socket;
import java.io.PrintWriter;
import java.io.*;
public class ClientTest
{
private static Socket socket;
private static PrintWriter printWriter;
private static BufferedReader myIn = new BufferedReader(new InputStreamReader(System.in));
private static String message;
public static void main(String[] args)
{
{
try
{
socket = new Socket("localhost",10005);
while(true) {
printWriter = new PrintWriter(socket.getOutputStream(),true);
System.out.print(": ");
System.out.flush();
message = myIn.readLine();
printWriter.println(message);
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
}
It works all perfect, but the problem now is: it can only connect with 1 client. I tried already something with threads, but it didn't help at all...
So if someone knows how i can get the server accepts more connections, thank you.
Sorry for my bad english.

New Topic/Question
Reply




MultiQuote






|