Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • 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

chat programe, kindly see the code and help me.

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you clear this doubt for me i shall really be grateful, as it is my project.
the below code is chat program which runs really fine in console.
so, i need this convert into applet.i have many problem regarding it.
1.how can i make TextField takes the input from user inplace of System.in.
2.do this particular program, if turn into applet requires to have signature or certificates.
i fail to make this into applet, please guide me..
import java.io.*;
import java.net.*;
public class RunTCPClient implements ChatClient
{
public RunTCPClient()
{
}
public void userHasEntered(String who)
{
System.out.println("---"+who+" has entered--");
}
public void userHasLeft(String who)
{
System.out.println("---"+who+" has left---");
}
public void incomingChat(String who,String chat)
{
System.out.println("<"+who+">"+chat);
}
public void disconnect()
{
System.out.println("chat server connection closed");
System.exit(0);
}
public static void main(String args[])
{
int port=8080;

String portStr=System.getProperty("port");
if(portStr!=null)
{
try
{
port=Integer.parseInt(portStr);
}
catch(Exception ignore)
{}
}
String hostName=System.getProperty("host");
if(hostName==null)hostName="localhost";

try
{
Socket clientSocket=new Socket(hostName,port);
DataOutputStream chatOutputStream=new DataOutputStream(clientSocket.getOutputStream());

DataInputStream chatInputStream=new DataInputStream(clientSocket.getInputStream());
//here how should i take input from the user not from console but from textfield.
DataInputStream userInputStream=new DataInputStream(System.in);

System.out.println("connected to the chat server");

System.out.println("what name do you like to keep");
System.out.flush();
String myName=userInputStream.readLine();
//how should read from applet.
chatOutputStream.writeUTF(myName);

RunTCPClient thisClient=new RunTCPClient();

TCPChatReader reader=new TCPChatReader(thisClient,chatInputStream);

reader.start();

while(true)
{
String chatLine=userInputStream.readLine();
sendChat(chatOutputStream,chatLine);
}
}
catch(Exception e)
{
System.out.println("got exception");
e.printStackTrace();
System.exit(1);
}
}
public static void sendChat(DataOutputStream outStream,String line)throws IOException
{
outStream.writeInt(TCPChatMessageTypes.CHAT);
outStream.writeInt(line.length());
outStream.writeBytes(line);
}
}


 
Check your pockets for water buffalo. You might need to use this tiny ad until locate a water buffalo:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic