static void fun() { PrintStream toSoc; try { ServerSocket f = new ServerSocket(9090); while (true) { Socket t = f.accept(); BufferedReader fromSoc = new BufferedReader(new InputStreamReader(t.getInputStream())); String video = fromSoc.readLine(); System.out.println(video); searcher obj = new searcher(); boolean fs; fs = obj.search(video); if (fs == true) { System.out.println("stream will starts"); toSoc = new PrintStream(t.getOutputStream()); toSoc.println("stream starts"); } else { toSoc = new PrintStream(t.getOutputStream()); toSoc.println("sorry"); } } } catch (Exception e) { System.out.println(e); } }
private final Socket setupDataLink() throws java.io.IOException { Socket dataSocket = (passiveSocket != null) ? passiveSocket.accept() : new Socket(remoteNode, remotePort); // ensure timeout on reads. dataSocket.setSoTimeout(inactivityTimer); return dataSocket; }
public static void main(String[] ar) { int port = 6000; Date sysDate = new Date(); String sysDateStr2; sysDateStr2 = new SimpleDateFormat("yyyy-MM-dd").format(sysDate).toString(); try { ServerSocket ss = new ServerSocket(port); System.out.println("Waiting for a client to connect..."); System.out.println("client connected"); System.out.println(); String msg = null; String IP, Date; float upload, download; Socket socket = ss.accept(); InputStream sin = socket.getInputStream(); OutputStream sout = socket.getOutputStream(); DataInputStream in = new DataInputStream(sin); DataOutputStream out = new DataOutputStream(sout); while (true) { msg = in.readUTF(); // wait for the client to send a line of text. System.out.println("IP address:" + msg); IP = msg; msg = in.readUTF(); System.out.println("Upload:" + msg); upload = Float.parseFloat(msg); msg = in.readUTF(); System.out.println("Download:" + msg); download = Float.parseFloat(msg); System.out.println("Date:" + sysDateStr2); Date = sysDateStr2; recieveTrafficRates(IP, upload, download); out.writeUTF(msg); // in.read(b); out.flush(); System.out.println("Waiting for the next line..."); System.out.println(); } } catch (Exception x) { x.printStackTrace(); } }
private void daemon() { try { server = new ServerSocket(localPort); while (true) { Socket incoming = server.accept(); new FlickrFtpd(incoming).start(); } } catch (Exception e) { // usually network errors (including timeout) if (server != null) try { server.close(); server = null; } catch (Exception e1) { } ; if (log) System.out.println("forced Server exit " + e); if (debug) e.printStackTrace(); } }