I want to send data from a computer to another using sockets (Server/Client), I searched for a solution but I didn't found any one helpful, can anyone help me please.
here is my Server code :
import java.net.*;
import java.io.*;
class server
{
public static void main(String arg[])
{
try
{
ServerSocket server = new ServerSocket(3006);
Socket s = server.accept();
System.out.println("connected!");
DataOutputStream dos = new DataOutputStream(s.getOutputStream());
dos.writeUTF("Welcom to socket");
}
catch(Exception e){
e.printStackTrace();
}
}
}
And this is my Client code: (192.168.1.5 is the Server's locale address)
import java.net.*;
import java.io.*;
class client
{
static InetAddress LocaleAdresse;
public static void main(String arg[])
{
try
{
System.out.println("client execute");
Socket s = new Socket("192.168.1.5", 3006);
DataInputStream dis = new DataInputStream (s.getInputStream());
String msg = dis.readUTF();
System.out.println(msg);
s.close();
}
catch(Exception e){
e.printStackTrace();
}
}
}