Java Reference
In-Depth Information
Here's the code for the server…
import java.io.*;
import java.net.*;
import javax.swing.*;
import java.util.*;
public class MediaServer
{
private static ServerSocket serverSocket;
private static fi nal int PORT = 1234;
public static void main(String[] args)
{
System.out.println("Opening port…\n");
try
{
serverSocket = new ServerSocket(PORT);
}
catch(IOException ioEx)
{
System.out.println(
"Unable to attach to port!");
System.exit(1);
}
do
{
try
{
Socket connection = serverSocket.accept();
//Step 1…
Scanner inStream =
new Scanner(connection.getInputStream());
//Step 2…
ObjectOutputStream outStream =
new ObjectOutputStream(
connection.getOutputStream());
String message = inStream.nextLine();
if (message.equals("IMAGE"))
sendFile("beesting.jpg", outStream);
if (message.equals("SOUND"))
sendFile("cuckoo.wav", outStream);
}
catch(IOException ioEx)
Search WWH ::




Custom Search