Java programming part 49 Java Sockets 2 : DataInputStream DataOutputStream

Published: 10 May 2012
on channel: Redemptie
6,891
15

Java Programming tutorial, Java Sockets and ServerSockets network, Using DataInputStream and DataOutputStream to send and receive data types over the network.
//server and socket code below
import java.net.*;
import java.io.*;


public class ServerClass {
public static void main(String[] args){
try {
ServerSocket serv = new ServerSocket(7777);
String message = " ";

Socket ss = serv.accept();
DataInputStream input = new DataInputStream(ss.getInputStream());

message = input.readUTF();
System.out.println(" From SOCKET : "+message);

DataOutputStream out = new DataOutputStream(ss.getOutputStream());
out.writeUTF("From SERVER with LOVE");

System.out.println("Socket connected to server OK!!!!");
ss.close();

} catch (IOException e) {
System.out.println("Server error!!");
}
}

}

/// client socket code
import java.net.*;
import java.io.*;

public class SocketClass {

public static void main(String[] args){
try{
Socket sock = new Socket("localhost",7777);

DataOutputStream out = new DataOutputStream(sock.getOutputStream());
out.writeUTF("From SOCKET with LOVE");
DataInputStream input = new DataInputStream(sock.getInputStream());
String strings = input.readUTF();
System.out.println("From SERVER : "+strings);

}catch(IOException e)
{
System.out.println("Socket Error!!!!");
}


}
}


On this page of the site you can watch the video online Java programming part 49 Java Sockets 2 : DataInputStream DataOutputStream with a duration of hours minute second in good quality, which was uploaded by the user Redemptie 10 May 2012, share the link with friends and acquaintances, this video has already been watched 6,891 times on youtube and it was liked by 15 viewers. Enjoy your viewing!