Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sockets

 
Charlie Flynn
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I would be very grateful if anyone could provide me with code to open a socket from an applet to an application running on the client machine, with the client's consent, that can to accept a continuous stream of integers. If it is not possible to create an applet with this functionality I would appreciate the code demonstrating this action in an application.
Many Thanks,
Charlie.
 
Raghav Mathur
Ranch Hand
Posts: 641
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is for the client :
import java.net.*;
import java.io.*;
public class tcpclient

{

public static void main(String args[]) throws Exception

{

Socket soc = new Socket("mac3",8001);
PrintWriter out = new PrintWriter(new OutputStreamWriter(soc.getOutputStream()));
BufferedReader inn = new BufferedReader(new InputStreamReader(soc.getInputStream()));
DataInputStream get = new DataInputStream(System.in);
System.out.println(inn.readLine());;
String str = get.readLine();
out.println(str);
out.flush();
// TO RECEIVE
//String mess = inn.readLine();
//System.out.println(mess);
}
}

this is for the server :
import java.net.*;
import java.io.*;
public class tcpserver
{
public static void main(String args[]) throws Exception
{
ServerSocket soc = new ServerSocket(8001);
System.out.println("server is ready");
Socket abc=soc.accept();
PrintWriter out = new PrintWriter(new OutputStreamWriter(abc.getOutputStream()));
BufferedReader inn = new BufferedReader(new InputStreamReader(abc.getInputStream()));
out.println("Connected");
out.flush();
System.out.println("Ready to read data");
String mess = inn.readLine();
System.out.println("message :"+mess+"from :"+abc.getInetAddress().getHostName());
} }

hope this helps .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic