Академический Документы
Профессиональный Документы
Культура Документы
What is UDP?
What is TCP?
Socket Programing
Networking is tightly integrated in Java. Java API provides the classes for creating sockets to facilitate
program communications over the Internet. Sockets are the endpoints of logical connections between
two hosts and can be used to send and receive data. Java treats socket communications much as it
treats I/O operations; thus programs can read from or write to sockets as easily as they can read from or
write to files. Java supports both TCP and UDP for communication.
To establish a server, you need to create a server socket and attach it to a port, which is where
the server listens for connections.
Note:
When you create a server socket, you have to specify a port (e.g., 8000) for the socket. When a
client connects to the server (line 43 in Client.java), a socket is created on the client. This socket
socket = server.accept();
System.out.println("Client accepted");
}
catch(IOException i)
{
System.out.println(i);
}
}
System.out.println("Closing connection");
// close connection
socket.close();
in.close();
}
catch(IOException i)
{
System.out.println(i);
}
}
Task:
Perform all exercises in the class.
Reading References:
1. http://www.oracle.com/technetwork/java/socket-140484.html
2. https://docs.oracle.com/javase/tutorial/networking/sockets/
3. https://docs.oracle.com/javase/7/docs/api/java/net/ServerSocket.html
4. http://www.geeksforgeeks.org/socket-programming-in-java/
5. https://netbeans.org/downloads/