summaryrefslogtreecommitdiff
path: root/src/Server/ChatServer.java
blob: 4a21cfd39cb98effbc87d1a5f151d4bb9289e4a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package Server;
import java.net.*;
import java.io.*;
import java.util.LinkedList;

public class ChatServer
{
	private ServerSocket service;
	private LinkedList<Connection> connections;
	
	public static final int portNum = 6667;
	
	ChatServer() throws IOException {
		this.service = new ServerSocket(portNum);
		this.connections = new LinkedList<Connection>();
	}
	/** Listening to port and opening a socket */
	public static void main(String[] args) throws IOException
	{
		ChatServer server;
		try
		{
			server = new ChatServer();
		} catch (IOException e)
		{
			System.err.println("Failed listening on port " + portNum + " (" + e + ")");
			return;
		}

		Socket soc = null;
		try
		{
			while (true)
			{
				soc = server.service.accept();
				Connection con = new Connection(soc);
				server.connections.add(con);
				con.start();
			}
		} catch (IOException e)
		{
			System.out.println(e);
		}

	}
}

/** Tasks
 *
 * * Allow listening on a different port (from command-line?)
 * * Have a test server running on cohens.org.il
 * * Send requests to all channels (use list)
 * * When passing a message (PRIVMSG) - inlcude the sender's nick.
 * * Keep channels up: PING occasionally
 * * Graphical interface for server
 */