File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

chat programe, kindly see the code and help me.

 
nima lama
Greenhorn
Posts: 19
  • 0
  • 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);
}
}


 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic