scroll to top
Stuck on your essay?
Get ideas from this essay and see how your work stacks up
Word Count: 1,507
Programming sockets in Java and writing simple SMTP client Programming sockets in Java In this section we will answer the most frequently asked questions about programming sockets in Java Then we will show some examples of how to write client and server applications Note In this tutorial we will show how to program sockets in Java using the TCPIP protocol only since it is more widely used than UDPIP Also All the classes related to sockets are in the javanet package so make sure to import that package when you program sockets How do I open a socket If you are programming a client then you would open a socket like this Socket MyClient MyClient new SocketMachine name PortNumber Where Machine name is the machine you are trying to open a connection to and PortNumber is the port a number on which the server you are trying to connect to is running When selecting a port number you should note that port numbers between 0 and 1023 are reserved for privileged users that is super user or root These port numbers are reserved for standard services such as email FTP and HTTP When selecting a port number for your server select one that is greater than 1023 In the example above we didnt make use of exception handling however it is a good idea to handle exceptions From now on all our code will handle exceptions The above can be written as Socket MyClient try MyClient new SocketMachine name PortNumber catch IOException e Systemoutprintlne If you are programming a server then this is how you open a socket ServerSocket MyService try MyServerice new ServerSocketPortNumber catch IOException e Systemoutprintlne When implementing a server you also need to create a socket object from the ServerSocket
@Kibin is a lifesaver for my essay right now!!
- Sandra Slivka, student @ UC Berkeley
Wow, this is the best essay help I've ever received!
- Camvu Pham, student @ U of M
If I'd known about @Kibin in college, I would have gotten much more sleep
- Jen Soust, alumni @ UCLA