• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

sockets

 
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.
 
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 .
 
Opportunity is missed by most people because it is dressed in overalls and looks like work - Edison. Tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic