-
Help with a problem
ok so.... my problem is.. its not sending the objects like it should.... and I'm not sure why.. so if someone could help me... I always posted this in the java section on DevX... but the threads I was reading seemed like that part was for beginners... so maybe someone can help me here if no one can over there.. heres the code, sorry for not putting it in the code format
import java.net.*;
import java.io.*;
public class SocketServer extends Thread
{
private static Socket socket = null;
static boolean forever = true;
static RTS2 rts = RTS2(0);
public static void main(String[] args) throws Exception
{
ServerSocket serverSocket = null;
try{
serverSocket = new ServerSocket(5455);
}catch (IOException e) {
System.err.println("Could not listen on port.");
System.exit(1);
}
Socket clientSocket = null;
try {
clientSocket = serverSocket.accept();
} catch (IOException e) {
System.err.println("Accept failed.");
System.exit(1);
}
while(forever)
{
try{
ObjectOutputStream oos =
new ObjectOutputStream(socket.getOutputStream());
oos.writeObject(rts.getCompany());
ObjectInputStream ois =
new ObjectInputStream(socket.getInputStream());
rts.setEnemy((Men)ois.readObject());
socket.close();
} catch (Exception e) {
System.out.println(e);
e.printStackTrace();
}
}
}
}
import java.net.*;
import java.io.*;
public class SocketClient
{
static boolean forever=true;
static RTS2 rts = RTS2(0);
static Socket socket = null;
static ObjectInputStream ois = null;
static ObjectOutputStream oos = null;
public static void main(String[] args) throws Exception
{
try {
socket = new Socket("josh", 5455);
ois = new ObjectInputStream(socket.getInputStream());
oos = new ObjectOutputStream(socket.getOutputStream());
} catch (UnknownHostException e) {
System.err.println("Don't know about host");
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't get I/O for the connection");
System.exit(1);
}
while(forever)
{
rts.setEnemy((Men)ois.readObject());
System.out.println("hello");
oos.writeObject(rts.getCompany());
oos.flush();
}
}
}
Similar Threads
-
By Irina in forum ASP.NET
Replies: 0
Last Post: 11-29-2002, 10:47 PM
-
Replies: 0
Last Post: 12-13-2001, 12:06 PM
-
By Roseta in forum VB Classic
Replies: 0
Last Post: 11-14-2001, 03:24 AM
-
By Ayman in forum VB Classic
Replies: 0
Last Post: 04-03-2000, 01:08 AM
-
By Jason Bock in forum VB Classic
Replies: 0
Last Post: 03-21-2000, 06:48 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks