Results 1 to 1 of 1
Thread: Client-Server creation
- 12-10-2012, 07:08 PM #1
Member
- Join Date
- Oct 2012
- Posts
- 21
- Rep Power
- 0
Client-Server creation
Hi.
I have a mighty task at hand, mostly because the deadline was trimmed by two weeks, so im in need of some advice. I have to create a client-server programm, which does the following:
The server must handle multiple conections (atleast three). The servers has to send a file to the client, the client manipulates it and shows the results of the file. Each have to show a lot of information during those proceses, error handling, files that dont have all the information needed. To write the whole task it would be a hassle to translate, need that time for other purposes. So im thinking how to make this happen. I have written a base code, which should handle multiple connections, is this a ok way to do it? Its nothing advanced, i just started networking today..
Any help, advice would be gratly appriciated!
Forgot one thing, when using readUTF(), it reads nothing or throws an error, what could be the possible reasons?
The server:
The Client:Java Code:import java.net.*; import java.io.*; class SendData implements Runnable { Socket newCon; SendData(Socket newCon) { this.newCon=newCon; System.out.println("Thread started!"); run(); } public void run() { try { OutputStream socketOut=newCon.getOutputStream(); BufferedWriter socketIn=new BufferedWriter(new OutputStreamWriter(socketOut)); socketIn.write("Hello, who are you?"); socketIn.close(); newCon.close(); } catch(IOException e) { System.out.println(e.getStackTrace()); } } } public class MyServer { int port; int active; ServerSocket socket=null; MyServer(int port) { this.port=port; System.out.println("Server started"); try { socket=new ServerSocket(port); } catch(IOException e) { System.out.println(e.getStackTrace()); } while(true) { try { Socket newCon=socket.accept(); SendData conection=new SendData(newCon); } catch(IOException er) { System.out.println(er.getStackTrace()); } } } public static void main(String[] args) { MyServer server=new MyServer(19999); } }
Java Code:package mess; import java.net.*; import java.io.*; public class MyClient { String host; int port; Socket server; MyClient(String host, int port) { this.host=host; this.port=port; System.out.println("Client started"); try { Socket server=new Socket(host, port); InputStream fromServer=server.getInputStream(); DataInputStream dataFrom=new DataInputStream(fromServer); System.out.println(dataFrom.readLine()); dataFrom.close(); server.close(); } catch(ConnectException b) { System.out.println("Could not connect!"); System.exit(0); } catch(IOException e) { e.printStackTrace(); } } public static void main(String[] args) { MyClient client=new MyClient("192.168.0.100",19999); } }Last edited by MustSeeMelons; 12-10-2012 at 07:11 PM.
Similar Threads
-
How to prevent hacking game client-server by decompile->modify->package new client
By chanphat01001 in forum CLDC and MIDPReplies: 3Last Post: 06-03-2012, 09:48 AM -
How to prevent hacking game client-server by decompile->modify->package new client
By chanphat01001 in forum Advanced JavaReplies: 1Last Post: 06-03-2012, 03:07 AM -
server-client; client sends a username to the server.
By lkcz in forum New To JavaReplies: 2Last Post: 09-24-2010, 11:31 AM -
Datagram Client and Server, client timer question
By saru88 in forum NetworkingReplies: 1Last Post: 10-05-2008, 03:12 PM -
Identify Client in Socket Client Server Application
By masadjie in forum NetworkingReplies: 1Last Post: 12-20-2007, 09:18 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks