java server socket example
Example: Create a socket connection java
import java.io.*;
import java.net.*;
public class MyServer
{
public static void main(String[] args)
{
try{
ServerSocket server = new ServerSocket(1234);
Socket serverSocket = server.accept();
InputStream in = serverSocket.getInputStream();
}catch(Exception e)
{
e.printStackTrace();
}
}
}
public class MyClient
{
public static void main(String[] args)
{
try{
Socket clientSocket = new Socket("localhost", 1234);
OutputStream out = clientSocket.getOutputStream();
}catch(Exception e)
{
e.printStackTrace();
}
}
}