Created
          October 31, 2010 05:56 
        
      - 
      
- 
        Save wasabili/656195 to your computer and use it in GitHub Desktop. 
    NetOthello Server
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import java.net.ServerSocket; | |
| import java.net.Socket; | |
| import java.io.InputStreamReader; | |
| import java.io.BufferedReader; | |
| import java.io.PrintWriter; | |
| import java.io.IOException; | |
| import java.util.*; | |
| public class NetOthelloServ { | |
| public static void main(String[] args){ | |
| Socket sockets[] = new Socket[2]; | |
| Scanner sc[] = new Scanner[2]; | |
| PrintWriter pw[] = new PrintWriter[2]; | |
| try { | |
| System.out.println("Started"); | |
| ServerSocket server = new ServerSocket(10000); | |
| for(int i=0;i<2;i++){ | |
| sockets[i] = server.accept(); | |
| sc[i] = new Scanner(sockets[i].getInputStream()); | |
| pw[i] = new PrintWriter(sockets[i].getOutputStream(), true); | |
| } | |
| } catch (Exception e) { | |
| e.printStackTrace(); | |
| } | |
| try{ | |
| pw[0].println(Othello.BLACK); | |
| pw[1].println(Othello.WHITE); | |
| for(int i=0;true;i=(i+1)%2){ | |
| int x = sc[i].nextInt(); | |
| int y = sc[i].nextInt(); | |
| pw[(i+1)%2].println(x+" "+y); | |
| } | |
| }catch(Exception e){ | |
| e.printStackTrace(); | |
| } | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment