A Client/Server example with .awt items?
Hi,
Is there anywhere an example of a simple Socker/ServerSocket code, that has .awt components like, the input goes into a TextArea and you can send through a TextField.
I have example for no .awt components, but for some reason I can't get them to work with... I'm kinda new here... So please?
Maybe you can help me?
Thanks...
hi..im doing a client server gui program....this is part of the server code....i cannot give u a complete working code coz...my program is way more complicated with 12 different 100 line class files..u can, at most , take a few hints!
/*server code*/
import java.io.*;
import java.net.*;
import java.util.*;
public class server4 extends Thread
{
String reply1="yes";
String reply2="no";
Vector v,onlynames;
int id=0;
ServerSocket ser;
Connecti2 con;
information info;
sendinfo pray;
val data;
Iterator vit,nameiter;
public server4()
{
v=new Vector(5);
onlynames=new Vector(5);
nameiter=onlynames.iterator();
try
{
ser=new ServerSocket(2991);
System.out.println(ser.toString());
}
catch(IOException e)
{
fail(e,"could not start server");
}
System.out.println("Server started...");
this.start();
}
public static void fail(Exception e,String str)
{
System.err.println(str+"."+e);
}
public void run()
{
try
{
while(true)
{
Socket client=ser.accept();
con=new Connecti2(client,id);
System.out.println("received client connection");
id++;
try
{
data=new val();
data=(val)con.streamfromclient.readObject();
onlynames.addElement(new String(data.nam));
/* sending in names for online list
will use onlynames vector as well as database permissionreply1/reply2 will be used as params for the listcomp ans client applet*/
permission3 p=new permission3();
p.ans="yes";
p.vect=onlynames;
try
{
con.streamtoclient.writeObject((permission3)p);
System.out.println("given permission");
}
catch(IOException e)
{
//showStatus("Something wrong!!" +e);
}
System.out.println(data.nam);
info=new information();
info.v.nam=data.nam;
info.v.pass=data.pass;
info.v.add=data.add;
System.out.println(info.v.nam);
info.os=con.streamtoclient;
info.is=con.streamfromclient;
v.addElement(info);
sendtoall(v,data.nam);
if(id==1)
{
pray=new sendinfo(v);
}
}
for the client similarly, use the getText option...make an ObjectOutputStream and send it across...again use setText when u want to display.
try and experiment...im doing the same here!