aspose file tools*
The moose likes Applets and the fly likes chat programe, kindly see the code and help me. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "chat programe, kindly see the code and help me." Watch "chat programe, kindly see the code and help me." New topic
Author

chat programe, kindly see the code and help me.

nima lama
Greenhorn

Joined: Jun 18, 2001
Posts: 19
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
 
subject: chat programe, kindly see the code and help me.
 
Similar Threads
4th time i am asking.Please see the code.
port number
Help wanted Urgently
Amit Agarwal jee!! please see this.
TCP Threaded Server Client Question