O'Reilly logo

C# for Java Developers by Adam Freeman, Allen Jones

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Sockets

The System.Net.Sockets namespace contains classes used to create applications that work directly with the Transmission Control Protocol (TCP) and the User Datagram Protocol (UDP). These classes build on the native socket classes discussed in the Programming with Native Sockets section later in this chapter.

Creating a TCP Client

To illustrate the use of the TCP client classes, we’ll read the index page from the Microsoft Web site. Here is a Java example using the Socket class:

import java.net.*; import java.io.*; public class SocketClient { public SocketClient() throws IOException, UnknownHostException { Socket x_socket = new Socket("www.microsoft.com", 80); PrintWriter x_writer = new PrintWriter(x_socket.getOutputStream(), true); x_writer.println("GET ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required