Your SlideShare is downloading. ×
Sockets in nach0s
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Sockets in nach0s

841
views

Published on

Published in: Technology, Education

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
841
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. SOCKETS IN NACH0S
      Socket types:
    • STREAM- Uses TCP which is realiable, stream oriented protocol.
    • 2. RAW- Provides RAW data transfer directly over IP protocol.
    • 3. DATAGRAM- Message oriented protocol.
  • 4. SOCKETS IN NACH0S
  • 8. SOCKETS IN NACH0S
      Programming Client-Servidor in JAVA
    • All the class located in the java.net package.
    • 9. Stream classes are in the java.io package.
  • 10. SOCKETS IN NACHOS
      How open a socket?
    • For programming a client, create an object of Socket class.
    Socket Client; try { Client = new Socket("Machine name", PortNumber); } catch (IOException e) { System.out.println(e); }
  • 11. SOCKETS IN NACH0S
    • For programinng a server, in this part how you open a socket.
    ServerSocket Service; try { Service = new ServerSocket (PortNumber); } catch (IOException e) { System.out.println(e); }
  • 12.
      When implementing a server you also need create a socket object.
    Socket clientSocket = null; try { clientSocket = Service.accept(); } catch (IOException e) { System.out.println(e); } SOCKETS IN NACH0S
  • 13. SOCKETS IN NACH0S
      How to create an imput Stream ?
    • You can use the DataImputStream class .
    DataInputStream input; try { input = new DataInputStream (Client.getInputStream()); } catch (IOException e) { System.out.println(e); }
  • 14. SOCKETS IN NACH0S
      How to create an output Stream ?
    • To the server socket using the class PrintStream or DataoutputStream of java.io
    PrintStream output; try { output = new PrintStream (Client.getOutputStream()); } catch (IOException e) { System.out.println(e); }
  • 15. SOCKETS IN NACH0S
      How to close socket?
    • You should always close the output and input stream before you close the socket.
    try { output.close (); input.close (); Client.close(); } catch (IOException e) { System.out.println(e); }