package com.codice.semanticmerge.examples.network;

import java.io.*;

class Socket {
    
    java.net.Socket socket;
    
    String getHostByName(String address) {
        // this method returns a host
        // when you give an IP address
        return calculateHostByName(address);
    }
    
    void listen() {
        // wait for connections on a port
        // and whatever is needed to listen
    }
    
    int recv(byte[] buffer) {
        try {
            InputStream in = socket.getInputStream();
            in.read(buffer);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    class ClientSocket {
    
        void connectTo(String addr, int port) throws Exception {
            // connect to a client
            socket = new java.net.Socket(addr, port);
        }
        
        int send(byte[] buffer) {
            int sent;
            
            try {
                OutputStream out = socket.getOutputStream();
                sent = out.write(buffer);
            } catch (Exception e) {
                e.printStackTrace();
            }
            
            return sent;
        }
        
    }
    
}