Socket Programming
import java.net.*;
import java.io.*;
class client
{
public static void main(String args[]) throws Exception
{
int character;
Socket socket = new Socket("192.168.1.4", 8765);
InputStream in = socket.getInputStream();
OutputStream out = socket.getOutputStream();
String str = "Hello!\n";
byte buffer[] = str.getBytes();
out.write(buffer);
while ((character = in.read()) != -1) {
System.out.print((char) character);
}
socket.close();
}
}
import java.io.*;
class client
{
public static void main(String args[]) throws Exception
{
int character;
Socket socket = new Socket("192.168.1.4", 8765);
InputStream in = socket.getInputStream();
OutputStream out = socket.getOutputStream();
String str = "Hello!\n";
byte buffer[] = str.getBytes();
out.write(buffer);
while ((character = in.read()) != -1) {
System.out.print((char) character);
}
socket.close();
}
}
Comments
Post a Comment