TCP PROGRAM:
Client :
import java.lang. ;
import java.io.*;
import java.net.*;
class client ( public static void main(string args[])
try ( socket skt = new socket("localhost", 1234);
sufferedReader in = new sufferedReader(new inputstreamReader(skt.getinputstream()));
system.out.print("Received string: '");
while (!in.ready()) (1 systemout.println(in.readLine());
// Read one line and output it
systemout.print(—\n");
in. close();
)
catch(Exception e)
system.out.print("whoops! It didn't work!\n");
_____________________________________
Server:
import java.lang.*;
import java.io.*;
import java.net.*;
class server { public static void main(string args[])
{
string data = "Toobie ornaught toobie";
try
{
serversocket srvr = new serversocket(1234);
socket skt = srvr.accept();
system. out. print("server has connected!\n");
Printwriter out = new Printwriter(skt.getoutputstream(), true); system.out.print("sending string: '" + data + "'\n"); out.print(data); out.close();
skt. closed; srvr. closed;
}
catch(Exception e)
{
system.out.print("whoops! It didn't work!\n");
}
}
No comments:
Post a Comment