• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

sockets

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 641
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
 
If you try to please everybody, your progress is limited by the noisiest fool. And this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic