Networked universe using Sockets

A while ago I wrote a simple client to client chat program with sockets using a server port. Is it feasable to adapt the code so that instead of just transfering text I can have another avatar traversing the same universe simultaniously from a remote workstation or am I being too ambitious (its intended for over an intranet and not the Internet)?

I woukd suggest to put the avatar-model to a webspace and to transfer only the URL of it. So the other client itself can fetch the data from this URL and display it.

Similar Messages

  • How to make a peer to peer connection in a network using sockets

    My Project is about a multi agent meeting scheduling system.. I've kept the DB in the server and I only use the server to retrieve data from the database. I have used sockets to communicate with the server.
    Each peer in the network is an agent for a perticular user and these agents will be communicating with each other for negotiation purposes..
    The problem I have is that, I couldnt communicate wit other peers using sockets.. I couldnt find any sample java code of sockets to overcum this problem.f sumone has a sample code plz send me.
    And if there is a more efficient and easy way I can connect these peers except sockets, plz tell me and if u have a sample java code plz be kind enough to send.
    This is my final year project in the University
    Thank you
    Sajini De Silva ([email protected])

    Hi Sajinidesilva,
    I think you'll find more support in the [JXTA Community|https://jxta.dev.java.net/] for your project. Also, there's an interesting article to start with : [Introduction to the Peer-to-Peer Sockets Project|http://www.onjava.com/pub/a/onjava/2003/12/03/p2psockets.html].

  • Networking Using Socket

    Hi,
    My team have developed a real-time remote network monitoring system. It consists of server and agent. What the agent does is send the network traffic data to server every one second by using socket. Each second we send the data to the same socket and yes we already make sure that the socket and streams used are closed after data being sent. However I still see a lot of SocketException once in a while whenever the agent tries to send the data.
    1. How can I solve this error ?
    2. Is it possible that I connect to my server just once without closing the connection and still able to send the data every second ?
    Thank you for your time.
    Regards,
    Mustafa
    Below is the code, called every one second :
          * This method sends itself into the server using compressed input/output
          * stream and then will receive back the instance of "replied" CRequest and
          * then further returns it.
          * @return CRequest
         public CRequest sendRequest() {
              SSLSocket server = null;
              GZIPOutputStream gos = null;
              ObjectOutputStream out = null;
              BufferedOutputStream bos = null;
              GZIPInputStream gis = null;
              ObjectInputStream in = null;
              try {
                   SSLSocketFactory sslFact = (SSLSocketFactory) SSLSocketFactory
                             .getDefault();
                   server = (SSLSocket) sslFact.createSocket(hostname, port);
                   String set[] = new String[] { "SSL_RSA_WITH_NULL_MD5" };
                   server.setEnabledCipherSuites(set);
                   server.setReceiveBufferSize(48000);
                   server.setSendBufferSize(48000);
                   if (milisecTimeout != 0) {
                        server.setSoTimeout(milisecTimeout);
                   gos = new GZIPOutputStream(server.getOutputStream());
                   bos = new BufferedOutputStream(gos, 48000);
                   out = new ObjectOutputStream(bos);
                   // /* Can we actually send ourselves and then receive ourselves?*/
                   out.writeObject(this);
                   out.flush();
                   bos.flush();
                   gos.finish();
                   gis = new GZIPInputStream(server.getInputStream());
                   in = new ObjectInputStream(new BufferedInputStream(gis, 48000));
                   /* Returning the newly modified request with results */
                   return (CRequest) in.readObject();
              } catch (Exception e) {
                   System.out.println("trouble sending request" + e);
              } finally {
                   if (gos != null) {
                        try {
                             gos.close();
                             // System.out.println("GOS closed..");
                        } catch (IOException e) {
                             // TODO Auto-generated catch block
                             e.printStackTrace();
                        gos = null;
                   if (out != null) {
                        try {
                             out.close();
                             // System.out.println("OUT closed..");
                        } catch (IOException e) {
                             // TODO Auto-generated catch block
                             e.printStackTrace();
                        out = null;
                   if (gis != null) {
                        try {
                             gis.close();
                             // System.out.println("GIS closed..");
                        } catch (IOException e) {
                             // TODO Auto-generated catch block
                             e.printStackTrace();
                        gis = null;
                   if (in != null) {
                        try {
                             in.close();
                             // System.out.println("IN closed..");
                        } catch (IOException e) {
                             // TODO Auto-generated catch block
                             e.printStackTrace();
                        in = null;
                   if (server != null) {
                        try {
                             server.close();
                        } catch (IOException e) {
                             // TODO Auto-generated catch block
                             e.printStackTrace();
                        server = null;
                   System.gc();
              return null;
         }

    I've been trying to modify my sendRequest function, so that It will only open and close the connection ONCE. As long as the connection is open I need to be able to send some data to the server. However I've been getting errors and stuffs like that.
    Exception:
    java.io.NotSerializableException: java.io.BufferedOutputStream
    +     at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1081)+
    +     at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1375)+
    +     at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1347)+
    +     at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)+
    +     at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)+
    +     at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:302)+
    +     at com.inetmon.jn.commobj.CRequest.sendRealTimeRequest(CRequest.java:385)+
    +     at com.inetmon.jn.core.internal.CaptureEngine.sendDataBackToServer(CaptureEngine.java:1420)+
    +     at com.inetmon.jn.core.internal.CaptureEngine$4.actionPerformed(CaptureEngine.java:2384)+
    +     at javax.swing.Timer.fireActionPerformed(Timer.java:271)+
    +     at javax.swing.Timer$DoPostEvent.run(Timer.java:201)+
    +     at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)+
    +     at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)+
    +     at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)+
    +     at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)+
    +     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)+
    received is null
    +     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)+
    +     at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)+
    The constructor which only be called once.
    public CRequest(Cookie cookie, int id, Object information, String hostname,
                   int port) {
              this.cookie = cookie;
              this.type = RequestConstants.AGENT_SEND_REALTIME_DATA;
              this.id = id;
              this.information = information;
              this.hostname = hostname;
              this.port = port;
              try {
                   SSLSocketFactory sslFact = (SSLSocketFactory) SSLSocketFactory
                             .getDefault();
                   server = (SSLSocket) sslFact.createSocket(hostname, port);
                   String set[] = new String[] { "SSL_RSA_WITH_NULL_MD5" };
                   server.setEnabledCipherSuites(set);
                   server.setReceiveBufferSize(48000);
                   server.setSendBufferSize(48000);
                   if (milisecTimeout != 0) {
                        server.setSoTimeout(milisecTimeout);
                   gos = new GZIPOutputStream(server.getOutputStream());
                   bos = new BufferedOutputStream(gos, 48000);
                   out = new ObjectOutputStream(bos);
              } catch (Exception e) {
                   System.out.println("trouble creating socket" + e);
         }The send request, which sends data whenever I want.
         public CRequest sendRealTimeRequest() {
              try {
                   // gos = new GZIPOutputStream(server.getOutputStream());
                   // bos = new BufferedOutputStream(gos, 48000);
                   // out = new ObjectOutputStream(bos);
                   // /* Can we actually send ourselves and then receive ourselves?*/
                   out.writeObject(this);
                   // out.flush();
                   // bos.flush();
                   // gos.finish();
                   gis = new GZIPInputStream(server.getInputStream());
                   in = new ObjectInputStream(new BufferedInputStream(gis, 48000));
                   /* Returning the newly modified request with results */
                   System.out.println("managed to send once");
                   return (CRequest) in.readObject();
              } catch (Exception e) {
                   e.printStackTrace();
              return null;
         }

  • Send html page (with images) using sockets

    I am trying to implement http and am coding this using sockets. So it is a simple client-server set up where the browser queries my server for a webpage and it should be shown. The html itself is fine, but I can't get any of the images to show up! All of my messages give me a status "200 OK" for the images, so I cant understand what my problem is!
    Also, is the status and header lines supposed to be shown in the browser? I didnt think so but it keeps showing up when I query a webpage.
    Please help!
    import java.io.* ;
    import java.net.* ;
    import java.util.* ;
    public final class WebServer
         public static void main(String argv[]) throws Exception
              // Set the port number.
              int port = 8888;
              // Establish the listen socket.
              ServerSocket ssocket = new ServerSocket(port);
              // Establish client socket
              Socket csocket = null;
              // Process HTTP service requests in an infinite loop.
              while (true)
                   // Listen for a TCP connection request.
                   // (note: this blocks until connection is made)
                   csocket = ssocket.accept();     
                   // Construct an object to process the HTTP request message.
                   HttpRequest request = new HttpRequest(csocket);
                   // Create a new thread to process the request.
                   Thread thread = new Thread(request);
                   // Start the thread.
                   thread.start();
    final class HttpRequest implements Runnable
         final static String CRLF = "\r\n";
         Socket socket;
         // Constructor
         public HttpRequest(Socket socket) throws Exception
              this.socket = socket;
         // Implement the run() method of the Runnable interface.
         public void run()
              try
                   processRequest();
              catch (Exception e)
                   System.out.println(e);
         private static void sendBytes(FileInputStream fis, OutputStream os)
         throws Exception
            // Construct a 1K buffer to hold bytes on their way to the socket.
            byte[] buffer = new byte[1024];
            int bytes = 0;
           // Copy requested file into the socket's output stream.
           while((bytes = fis.read(buffer)) != -1 ) {
              os.write(buffer, 0, bytes);
              os.flush();
         private static String contentType(String fileName)
              fileName = fileName.toLowerCase();
              if(fileName.endsWith(".htm") || fileName.endsWith(".html")) {
                   return "text/html";
              if(fileName.endsWith(".jpg") || fileName.endsWith(".jpeg") ) {
                   return "image/jpeg";
              if(fileName.endsWith(".gif")) {
                   return "image/gif";
              return "application/octet-stream";
         private void processRequest() throws Exception
              // Get a reference to the socket's input and output streams.
              InputStream is = socket.getInputStream();
              DataOutputStream os = new DataOutputStream(socket.getOutputStream());
              // Set up input stream filters.
              InputStreamReader ir = new InputStreamReader(is);
              BufferedReader br = new BufferedReader(ir);
              // Get the request line of the HTTP request message.
              String requestLine = br.readLine();
              // Display the request line.
              System.out.println();
              System.out.println(requestLine);
              // Get and display the header lines.
              String headerLine = null;
              while ((headerLine = br.readLine()).length() != 0)
                   System.out.println(headerLine);
              // Extract the filename from the request line.
              StringTokenizer tokens = new StringTokenizer(requestLine);
              tokens.nextToken();  // skip over the method, which should be "GET"
              String fileName = tokens.nextToken();
              // Prepend a "." so that file request is within the current directory.
              fileName = "C:\\CSM\\Networking\\Project1" + fileName;
              // Open the requested file.
              FileInputStream fis = null;
              boolean fileExists = true;
              try {
                   fis = new FileInputStream(fileName);
              } catch (FileNotFoundException e) {
              fileExists = false;
              // Construct the response message.
              String statusLine = null;
              String contentTypeLine = null;
              String entityBody = null;
              if (fileExists) {
              statusLine = "200 OK" + CRLF;
              contentTypeLine = "Content-type: " +
                   contentType( fileName ) + CRLF
                   + "Content-length: " + fis.available() + CRLF;
              else {
              statusLine = "404 Not Found" + CRLF;
              contentTypeLine = "Content-type: text/html" + CRLF;
              entityBody = "<HTML>" +
                   "<HEAD><TITLE>Not Found</TITLE></HEAD>" +
                   "<BODY>Not Found</BODY></HTML>";
              // Send the status line.
              os.writeBytes(statusLine);
              System.out.println(statusLine);
              // Send the content type line.
              os.writeBytes(contentTypeLine);
              System.out.println(contentTypeLine);
              // Send a blank line to indicate the end of the header lines.
              os.writeBytes(CRLF);
              // Send the entity body.
              if (fileExists)     
                   sendBytes(fis, os);
                   fis.close();
              // file does not exist
                     else
                   os.writeBytes(entityBody);
              // Close streams and socket.
              os.flush();
              os.close();
              br.close();
              socket.close();
    }

    ok. i figured it out. STUPID mistake. i forgot to include "HTTP/1.1" in my status line!!!

  • Connect applet to server port using sockets? Please help!!!

    I am trying to connect a java applet to game1.pogo.com:5285 which is their gaming port. I want to make it connect from my website which is ucichess.com
    The applet can be found here: http://ucichess.com/index.html and the java console gives me a bunch of weird errors if u can take a look at it:
    network: Disconnect connection to http://ucichess.com/applet/chess2/com/pogo/util/thin/e.class
    network: Cache entry found [url: http://ucichess.com/applet/chess2/com/pogo/util/thin/m.class, version: null]
    network: Connecting http://ucichess.com/applet/chess2/com/pogo/util/thin/m.class with proxy=DIRECT
    network: ResponseCode for http://ucichess.com/applet/chess2/com/pogo/util/thin/m.class : 304
    network: Encoding for http://ucichess.com/applet/chess2/com/pogo/util/thin/m.class : null
    network: Disconnect connection to http://ucichess.com/applet/chess2/com/pogo/util/thin/m.class
    network: Connecting socket://ucichess.com:5285 with proxy=DIRECT
    Sun Jul 22 17:14:24 EDT 2007     Thread-198          ArenaServiceThin.error
    Sun Jul 22 17:14:24 EDT 2007     Thread-198          exception
    java.net.ConnectException: Connection refused: connect
         at java.net.PlainSocketImpl.socketConnect(Native Method)
         at java.net.PlainSocketImpl.doConnect(Unknown Source)
         at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
         at java.net.PlainSocketImpl.connect(Unknown Source)
         at java.net.SocksSocketImpl.connect(Unknown Source)
         at java.net.Socket.connect(Unknown Source)
         at java.net.Socket.connect(Unknown Source)
         at java.net.Socket.<init>(Unknown Source)
         at java.net.Socket.<init>(Unknown Source)
         at com.pogo.besl.thin.c.<init>(SourceFile)
         at com.pogo.besl.thin.a.<init>(SourceFile)
         at com.pogo.besl.arena.a.g(SourceFile)
         at com.pogo.besl.arena.a.a(SourceFile)
         at com.pogo.game.arena.chat.ChatArenaApplet.a(SourceFile)
         at com.pogo.game.arena.chat.ChatArenaApplet.b(SourceFile)
         at com.pogo.client.ping.b.run(SourceFile)
    network: Connecting http://ucichess.com/blank.html?confuser=-6956021725811422401 with proxy=DIRECT
    Applet.terminate(false, false)
    ChatArenaApplet.disposeLocals(false)
    InvalQueue thread exiting: InvalQueue-1-com.pogo.ui.a[panel8,0,0,458x403,invalid]
    ChatArenaApplet.disconnect()
    Applet.disposeLocals(false) - ChessTable
    network: Cache entry not found [url: http://ucichess.com/applet/chess2/META-INF/assets.txt, version: null]
    network: Connecting http://ucichess.com/applet/chess2/META-INF/assets.txt with proxy=DIRECT
    basic: Stopping applet ...
    basic: Removed progress listener: sun.plugin.util.GrayBoxPainter@106433d
    basic: Finding information ...
    basic: Releasing classloader: sun.plugin.ClassLoaderInfo@35dc95, refcount=0
    basic: Caching classloader: sun.plugin.ClassLoaderInfo@35dc95
    basic: Current classloader cache size: 2
    basic: Done ...
    basic: Joining applet thread ...
    basic: Destroying applet ...
    basic: Disposing applet ...
    basic: Quiting applet ...
    ChatArenaApplet.disposeGlobals()
    Timer thread exiting: ScrollbarButtonRepeater
    network: Cache entry found [url: http://ucichess.com/applet/chess2/com/pogo/ui/b.class, version: null]
    basic: Joined applet thread ...
    network: Connecting http://ucichess.com/applet/chess2/com/pogo/ui/b.class with proxy=DIRECT
    network: ResponseCode for http://ucichess.com/applet/chess2/com/pogo/ui/b.class : 304
    network: Encoding for http://ucichess.com/applet/chess2/com/pogo/ui/b.class : null
    network: Disconnect connection to http://ucichess.com/applet/chess2/com/pogo/ui/b.class
    network: Cache entry found [url: http://ucichess.com/applet/chess2/com/pogo/ui/q.class, version: null]
    network: Connecting http://ucichess.com/applet/chess2/com/pogo/ui/q.class with proxy=DIRECT
    network: ResponseCode for http://ucichess.com/applet/chess2/com/pogo/ui/q.class : 304
    network: Encoding for http://ucichess.com/applet/chess2/com/pogo/ui/q.class : null
    network: Disconnect connection to http://ucichess.com/applet/chess2/com/pogo/ui/q.class
    Applet.disposeGlobals - ChessTable
    Applet.terminate completed
    Is it possible for me to host the applet on my server and connect it to a remote server using sockets and verification or is that against java security?
    Applet.stop - ChessTable
    Applet.stop completed - ChessTable
    Applet.destroy - ChessTable
    Applet.destroy completed - ChessTable
    ChatArenaApplet.disconnect()

    Hi yoshistr, have you resolved your issue? If you have, do you mind sharing it with me?
    Thanks.

  • Send a picture file using sockets

    Hi,
    Could someone please tell me how I can send a picture file using sockets across a TCP/IP network? I have managed to do it by converting the file into a byte array and then sending it but I dont see the data back at the client when I recieve the file. I just see the byte array as having size 0 at client.
    Byte array size is correct at client side.
    //client code
    System.out.println("Authenticating client");
              localServer = InetAddress.getLocalHost();
              AuthConnection = new Socket(localServer,8189);
              out = new PrintWriter(AuthConnection.getOutputStream());
              InputStream is = AuthConnection.getInputStream();
              System.out.println(is.available());
              byte[] store = new byte[is.available()];
              is.read(store);
         ImageIcon image = new ImageIcon(store);
              JLabel background = new JLabel(image);
              background.setBounds(0, 0, image.getIconWidth(), image.getIconHeight());
              getLayeredPane().add(background, new Integer(Integer.MIN_VALUE));
    //extra code here
              catch (UnknownHostException e) {
    System.err.println("Don't know about host: LocalHost");
    System.exit(1);
              catch (IOException e) {
    System.err.println("Couldn't get I/O for "
    + "the connection to: LocalHost");
    System.exit(1);
    //server code
                   DataOutputStream out = new DataOutputStream(incoming.getOutputStream());
                   FileInputStream fin = new FileInputStream("3trees.gif");
                   byte[] b = new byte[fin.available()];
                   int ret = fin.read(b);
                   out.write(b);

    i used OutputStream as
    OutputStream out = incoming.getOutputStream(); and flushed the stream too.
    But I still get the same output on the client side. I tried sending a string and it works , but I cant seem to be able to populate the byte array on the client side. It keeps showing zero. Please advise.
    Thank you.

  • Reading / Writing files using Sockets

    Hi there guys,
    I am fairly new to this forum. I have been having a problem for the past three days. I am implementing a client/server implementation using Sockets which is a submodule of a project I am working on. What I want is that a files content are read and transferred over the network to the server that writes it down to a different file .
    What the code presently does is :
    <<<<Client Code >>>>
    It reads a file input.txt and sends the content over the network to the server.
    <<<< Server Code >>>
    It reads the incoming data from the client and writes the data out to a file called output.txt
    What I want now is that the server should read the file output.txt and send the contents to the client which reads it and then writes it down as a new file called serverouput.txt . After that I want to compare and see of the size of input.txt and serveroutput.txt . If both are same that means that data has been written reliably to the server.
    I have been trying to implement it for a long time and nothing seems to work out. I am posting the code for both client and server below. Any help in finalising things would be really appreciated.
    CLIENT CODE
    import java.awt.Color;
    import java.awt.BorderLayout;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.Date;
    import java.io.*;
    import java.net.*;
    class sc {
    static final int PORT = 4444;          //Change this to the relevant port
    static final String HOST = "127.0.0.1";
         //Change this to the relevant HOST,
    //(where Server.java is running)
    public static void main(String args[]) {
    try {
    System.out.print("Sending data...\n");
    Socket skt = new Socket(HOST, PORT);
                   // Set the socket option just in case server stalls
    skt.setSoTimeout ( 2000 );
                   skt.setSoKeepAlive(true);
    //Create a file input stream and a buffered input stream.
    FileInputStream fis = new FileInputStream("input.txt");
    BufferedInputStream in = new BufferedInputStream(fis);
    BufferedOutputStream out = new BufferedOutputStream( skt.getOutputStream() );
    //Read, and write the file to the socket
    int i;
    while ((i = in.read()) != -1) {
    out.write(i);
    //System.out.println(i);
                   // Enable SO_KEEPALIVE
    out.flush();
    out.close();
    in.close();
    skt.close();
    catch( Exception e ) {
    System.out.print("Error! It didn't work! " + e + "\n");
              catch( IOException e ) {
    System.out.print("Error! It didn't work! " + e + "\n");
    SERVER CODE
    import java.awt.Color;
    import java.awt.BorderLayout;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.Date;
    import java.io.*;
    import java.net.*;
    class ClientWorker implements Runnable {
    private Socket client;
    ClientWorker(Socket client) {
    this.client = client;
    public void run(){
    try      {
    FileOutputStream fos = new FileOutputStream("output.txt");
    BufferedOutputStream out = new BufferedOutputStream(fos);
    BufferedInputStream in = new BufferedInputStream( client.getInputStream() );
    //Read, and write the file to the socket
    int i;
    while ((i = in.read()) != -1) {
    out.write(i);
    //System.out.println(i);
    System.out.println("Receiving data...");
    out.flush();
    in.close();
    out.close();
    client.close();
    // srvr.close();
    System.out.println("Transfer complete.");
    catch(Exception e) {
    System.out.print("Error! It didn't work! " + e + "\n");
    class ss1 {
    ServerSocket server = null;
    ss1(){ //Begin Constructor
    } //End Constructor
    public void listenSocket(){
    try{
    server = new ServerSocket(4444);
    } catch (IOException e) {
    System.out.println("Could not listen on port 4444");
    System.exit(-1);
    while(true){
    ClientWorker w;
    try{
    w = new ClientWorker(server.accept());
    Thread t = new Thread(w);
    t.start();
    } catch (IOException e) {
    System.out.println("Accept failed: 4444");
    System.exit(-1);
    protected void finalize(){
    //Objects created in run method are finalized when
    //program terminates and thread exits
    try{
    server.close();
    } catch (IOException e) {
    System.out.println("Could not close socket");
    System.exit(-1);
    public static void main(String[] args){
    ss1 frame = new ss1();
         frame.listenSocket();
    }

    ............................................. After that I want to
    compare and see of the size of input.txt and
    serveroutput.txt . If both are same that means that
    data has been written reliably to the server.You don't need to do this. TCP/IP ensures the reliable transmition of data. By using a socket you are automaticaly sure that the data is reliably transmitted (Unless there is some sort of exception).
    To get the size of the files you can use a File object. Look it up in java.io package in API documentation.
    java-code-snippet (without error checking)
    File clientFile = new File("input.txt");
    clientFile.length();

  • Client/server application using sockets

    Hi there,
    I'm trying to create a client/server application using sockets where the client has a GUI of a membership application form for some sort of club. Basically, the user will enter their name, address, membership no. etc in to various Jtext fields and then press a JButton to submit these details to the server. The server will then hopefully just dump these details to a text file.
    Can anyone give me any examples, ideas on how to start, links etc.
    Thanks v. much in anticipation,
    Nick

    Take a browse of the tutorial on sockets: http://java.sun.com/docs/books/tutorial/networking/sockets/clientServer.html

  • Client & server can use different language when using socket for client/ser

    When building client/server applications using socket , is it that client and server do not need to use both Java as long as they implement the same networking protocol?
    Thanks a lot!

    thank you, DrClap!

  • Filestreaming using sockets

    I have written a server and a client for streaming a file. Client to server. I have tried a lot of code to get a file streamed from client to server, but either nothing happens or it's only 16 kb (byte array) arriving and the last result - the server keeps writing (never stops) to the file output making the file grow rapidly and far beyond the size of the transmitted file. I know that file streaming should be the same whether it's local file handling or using sockets. I have the local file streaming working fine, but converting it to sockets doesn't work. So this server/client is a new approach using byte array. Still doesn't work. Can anyone help? Alternatively give me a link to a working code for this job. Thank you. :)
    Client
    import java.io.*;
    import java.net.Socket;
    public class my_client {
         public static void main(String[] args) throws IOException{
                   String server = args[0];
                   int port = Integer.parseInt(args[1]);
                   String filename = args[2];
                   Socket socket = new Socket(server, port);
                   System.out.println("Connected at " + socket.getLocalSocketAddress());
                   OutputStream fout = socket.getOutputStream();
                   FileInputStream bis = new FileInputStream(filename);
                   byte[] data = new byte[1024];                         
                   int totalTx = bis.read(data);          
                   while(totalTx != -1){
                        fout.write(data, 0, totalTx);
                        fout.flush();
                   socket.shutdownOutput();
                   socket.close();
    }Server
    import java.net.*;
    import java.io.*;
    public class my_server {
         public static void main(String[] arg) throws IOException{
              if(arg.length != 1) throw new IllegalArgumentException("Parameter: <port>");
         int servPort = Integer.parseInt(arg[0]);
         ServerSocket servSock = new ServerSocket(servPort);
         while(true){
              Socket clntSock = servSock.accept();
              SocketAddress clntAddress = clntSock.getRemoteSocketAddress();
              System.out.println("Handling client at " + clntAddress);
              InputStream in = clntSock.getInputStream();
              FileOutputStream fout = new FileOutputStream("incomming.txt");
              byte[] data = new byte[1024];
              int totalRx = in.read(data);
              while(totalRx != -1){
                   fout.write(data, 0, totalRx);
              fout.close();
              in.close();
              clntSock.close();
    }

    1. Your read are outside your while loops.
    2. There is a whole protocol standard for file transfer called FTP = File Transfer Protocol.
    3. There is also a networking forum where socket questions are best asked.
    4. Your sever is single threaded so you can only handle one read at a time.

  • Folder transfer using sockets

    Is there anyway to transfer the whole folder including the subfolders
    using sockets.
    i can transfer the all the files one by one
    but it needs lot of coding like making subfolders in the destination and etc.
    i need to send a folder using a single outputstream
    Thanks
    Ananth

    Ananthakumaran wrote:
    tar and untar will take some time Really? Have you measured that?
    I'll bet if you look, the time it takes is completely dominated by the need to read the files on one side and write the files on the other. Since any copy program has to do the same thing, this should be no slower than any other method.
    and mostly my app is used to transfer large size file
    i need something which can send folder like a single file without any >>> overhead >>>Everything you do has overhead. You want to send files and folders over the network. Using tar to serialize that structure has very little overhead. I doubt the overhead will be visible given the need to actually read and write the files.
    Darren

  • Using Sockets TCP/IP to connect through Proxies and Firewalls

    How to do in a Client/server Application using Sockets TCP/IP to connect through Proxies and Firewalls?
    How to implement the HTTP Tunnelling in this case?
    the code in Client to connect to server is:
    SSLSocketFactory sslFact = (SSLSocketFactory)SSLSocketFactory.getDefault();
                   socket = (SSLSocket)sslFact.createSocket(c.site, c.PORT);
              String [] enabledCipher = socket.getSupportedCipherSuites ();     
                   socket.setEnabledCipherSuites (enabledCipher);
                   out = new ObjectOutputStream(socket.getOutputStream());
                   in = new ObjectInputStream(socket.getInputStream());
    The Server is an executable Standalone Application with a main Function � How to do to convert this Server in a Servlet Application?
    the code in Server to wait client connections is:
    Runtime.getRuntime().addShutdownHook(new ShutdownThread(this));
              try {
                   SSLServerSocketFactory factory = (ServerSocketFactory) SSLServerSocketFactory.getDefault();
                   SSLServerSocket sslIncoming =
                        (SSLServerSocket) factory.createServerSocket (PORT);
                   String [] enabledCipher = sslIncoming.getSupportedCipherSuites ();
                   sslIncoming.setEnabledCipherSuites (enabledCipher);
              while(running) {
                        SSLSocket s = (SSLSocket)sslIncoming.accept();
                   newUser(s, pauseSyn);
              } catch (IOException e) { System.out.println("Error: " + e); }
    some links or code sample?
    Thanks in Advance

    Did you see this: Networking Properties?
    Including
    SOCKS protocol support settings
    and
    http.proxyHost (default: <none>)
    http.proxyPort (default: 80 if http.proxyHost specified)
    http.nonProxyHosts (default: <none>
    ftp.proxyHost (default: <none>)
    ftp.proxyPort (default: 80 if ftp.proxyHost specified)
    ftp.nonProxyHosts (default: <none>)

  • Error while creating a BO Universe (using IDT) on top of SAP HANA Calculation View with Input Parameters

    Hi All..
          We are trying to create a Universe (using IDT-Version4.0) on top of the HANA Calculation view. The Calculation view has 4 input parameters, So
    in Universe side we have created the respective prompts. For the creation of derived table we have used the following code
    SELECT *
    FROM "_SYS_BIC"."<schema_name>.<CV_Calculation_View_test>"
    'PLACEHOLDER'=('$$IP_A$$','@Prompt(A)'),
    'PLACEHOLDER'=('$$IP_B$$','@Prompt(B)'),
    'PLACEHOLDER'=('$$IP_C$$','@Prompt(C)'),
    'PLACEHOLDER'=('$$IP_D$$','@Prompt(D)')
    While validating the above code we are getting an error.
    I have attached the snapshot of that error for your reference. Please find the attachment and help me in resolving it.
    Thanks in advance.

    Hello George,
    I don't have any personalization set on the info space. Also I am using mapped Account in BI to connect to HANA. The confusing part is that it is able to validate the infospace with the input parameters and index it. However query does not return any results. I even tried running the same query which explorer sends to HANA in the SQL editor and there too the same results,the query does not return anything. The model does return data when I do a data preview and if accessed from other tools like AAO.
    Also when I use SSO connection to HANA, indexing of the infospace fails. Where can I see the error log?
    Thanks,

  • How can I  connect to SQL server database thru local network by using JSP?

    I'm currently doing a project by using JSP..And I need to display record from the SQL Server database in our school's local network. May I know how can I do that? How can I write the code so that I can able to access the SQL Server databsase Throught school's network by using JSP? Please tell me step by step how can I do that. I'm using Tomcat 4.1 as Web Server. And I had J2SE and J2EE installed in my computer.

    first you have to establish a ODBC DSN on your computer,
    that connects to the database...you can do that from your control pannel.
    i assume that the TOMCAT server is residing on your computer....(if the webserver is in other computer then you would have to create a System DSN on the data sources ODBC option in the settings>control pannel of that machine)
    then you can use that DSN name to connect to the data base from the class file....for further assistance on how to create the class that access the tutorials in sun site.
    regards
    G

  • Unable print scheduled report on network printer using BOEXI 3.0

    Hi,
    I'm unable to print a scheduled report on network printer using BOE XI 3.0. I get the following error
    Error Message: Error in File ~ce6a054be1a25b52.rpt: Request cancelled by the user. ]
    Has anyone encountered this kind of problem and know what the solution is?
    Thanks,

    Hey Falk,
    Thanks for the response.
    I can print on a network printer after I changed 'Crystal Reports Job Server' to run under a user account that has privileges to access the printer.
    To answer your questions regarding the problem:
    >Can you schedule the report successfully ?
    >>Yes I was able to schedule the report successfully
    >Can you print the report successfully?
    >>NO the scheduled task would fail with the error message as posted above.
    Thanks,

Maybe you are looking for

  • Brand New MacBook Pro Cannot Connect to Airport Express

    Hi all, Been reading through these pages and I think there are many others with the same problem as me but with no real answer, I thought it wouldn't hurt to ask anyway. I have an Airport Express which I bought a couple of years ago. It initially wor

  • ITunes 7 will not open but quicktime works

    I just tried upgrading and installing the new version of itunes however when i try to open iTunes, it wont open. If I try to run the setup again and 2 options come up to either repair or remove iTunes from my computer. If I select repair, it goes thr

  • Ad-Hoc Query (Personal Data Infotype)

    Hi, Our employees are able to update/correct any personal details (name changes, addresses, NI number etc) using ESS.These changes are reflected in the personal data infotype. I would like ot run an ad-hoc query to pick up any personal changes that e

  • What are the data files in the Proxies folder?

    In the iMovie Projects folder tree there are folders called Proxies. In that folder there is a folder called the name of the projects events folder, twice, with %20 for spaces and such. In that folder there are a large number of data files like 2010.

  • Error running Adobe Download Assistant for PS Elements 11

    I'm logged into my Adobe account. I'm on a MacBook Pro running OS x 10.6.8. I use Chrome as my browser but have tried this with Safari as well with the same result. I download the dmg for Adobe Download Assistant and when I run it, it launches ADA bu