Sending stuff over the network

Hi!
How do you send int:s, floats and all other basic datatypes trough the network? Is there any package that can make them all to byte[] and back or do you have to write all yourself?

See java.io.ObjectOutputStream and ObjectInputStream.
Essentially, these classes "package" java primitives and objects (that implement java.io.Serializable) for output and "unwrap" them for input.

Similar Messages

  • Send BufferedImage over the network

    I have already successfully setup a client/server connection. The issue, is when I send the BufferedImage over the network, it says:
    "Caused by: java.io.NotSerializableException: java.awt.image.BufferedImage"
    Can someone please tell me how to fix this?

    Like the exception say, BufferedImage is not serializable. You cannot serialize it. The problem will go away if you don't try to serialize it. Of course, that doesn't answer the question you really meant to ask... which I'll leave for somebody else.

  • Trouble sending files over the network.

    I have a network application that corrupts any files that it sends, although the received file is very close (but never exact) to the number of bytes it should be. There is a socket client that each client has, and the Packet data structure is searializable and simply contains a string message and the byte[]. Am I doing something wrong?
    Here is my code for Sending:
    ObjectOutputStream toOtherClient = new ObjectOutputStream(client.getOutputStream());
    ObjectInputStream fromOtherClient = new ObjectInputStream(client.getInputStream());
    Packet fileRequest = (Packet)fromOtherClient.readObject();
    File file = new File(DefaultConfig.defaultFileDirectory+"\\"+fileRequest.getMessage());
    FileInputStream fromDisk = new FileInputStream(file);
    BufferedInputStream fromDiskBuffered = new BufferedInputStream(fromDisk);
    byte[] buffer = new byte[maxPayload];
    while(fromDiskBuffered.available() > 0)
         if (fromDisk.available() > maxPayload)
              fromDiskBuffered.read(buffer);
              toOtherClient.writeObject(new Packet(Packet.Command.File,"",buffer));
         else
              buffer = new byte[fromDiskBuffered.available()];
              fromDiskBuffered.read(buffer);
              toOtherClient.writeObject(new Packet(Packet.Command.File,"",buffer));
    fromDiskBuffered.close();
    fromDisk.close();
    toOtherClient.writeObject(new Packet(Packet.Command.File,"ack"));
    fromOtherClient.close();
    toOtherClient.close();
    client.close();Here is my code for recieving:
    Socket client = new Socket(host, Integer.parseInt(port));
    ObjectOutputStream toOtherClient = new ObjectOutputStream(client.getOutputStream());
    ObjectInputStream fromOtherClient = new ObjectInputStream(client.getInputStream());
    FileOutputStream toDisk = new FileOutputStream(DefaultConfig.defaultFileDirectory+"//"+whatFile); BufferedOutputStream toDiskBuffered = new BufferedOutputStream(toDisk);
    toOtherClient.writeObject(new Packet(Packet.Command.File,whatFile));
    Packet incoming;
    while(true)
         incoming = (Packet)fromOtherClient.readObject();
         if (incoming.getMessage().equals("ack"))
              break;
         byte[] fileData = (byte[])incoming.getData();
         toDiskBuffered.write(fileData);
    toDiskBuffered.flush();
    toDiskBuffered.close();
    toDisk.close();
    fromOtherClient.close();
    toOtherClient.close();
    client.close();

    You're assuming that available() gives you the total length of the file, which it doesn't, and you're ignoring the result returned by the read call, so you're assuming you've read data you may not have read.
    I would rethink the tactic of reading the entire file into a single buffer - this doesn't scale. It's only safe if you know that the file size has an upper bound and that this is relatively low.

  • Make a voice transmitter over the network?

    Hi i have read that it is possible in javax.sound to send or transmit live audio over the network or simply make a VoIP phone using the javax.sound api. I would like to ask if how can I be able to send the sound of the network. I have this step by step instruction about capturing and sending the voice in the network:
    • Use TargetDataLine for streaming capture
    • The TargetDataLine is wrapped in an AudioInputStream so that it can be converted to the network format with AudioSystem
    • a capture thread reads from the converted AudioInputStream and writes it to the network connection's OutputStream.
    Here is my code:
         audioFormat = getAudioFormat();
            DataLine.Info dataLineInfo = new DataLine.Info(TargetDataLine.class, audioFormat);
         targetDataLine = (TargetDataLine)AudioSystem.getLine(dataLineInfo);
         audioInputStream = new AudioInputStream(targetDataLine);I am not sure about this code but I am sure that there must be a targetDataLine associated in sending the voice. Please help me with this. Thank you.

    TargetDataLines are for reading from, SourceDataLines are for writing to, and AudioInputStreams are for loading/saving from a file.
    That said, there will be a TargetDataLine you can read from that's associated with your microphone. You create an AudioInputStream to read from the TargetDataLine (which is just an argument in the constructor), and then you can do...
    AudioSystem.write
    Give it the AIS associated with hte TDL, and you can either have it write it to a file or to an output stream. If that output stream was, say...an IP socket stream...then you could send it over the network to the other side...where you'd then need to construct an AudioInputStream to read it from the IP socket stream, and then to play it, you'd read some data from the AIS and write it to a SourceDataLine.
    Here are some resources to help you with the JavaSound stuff.
    JavaSound Example code (take a look at SimpleAudioPlayer & SimpleAudioRecorder in the Audio Playback and Recording section)
    [http://www.jsresources.org/examples/]
    Programmer's guide
    [http://java.sun.com/j2se/1.5.0/docs/guide/sound/programmer_guide/contents.html]
    And then just the normal Java SE6 API
    [http://java.sun.com/javase/6/docs/api/]

  • Fax over the network with HP LaserJet 400 ColorMFP M475dw

    Hi there, I was trying to send fax over the network with  HP LaserJet 400 ColorMFP M475dw, I have connected the printer/scan/fax on a wired network, just have 3 computers on it, all of them  can scan or print. But I can't find any option to just FAX from Microsoft Word or Adobe Acrobat Reader, going to File ---> Print ---> and select M475dw "FAx", I installed the lasted version of the drivers downloaded from hp.com and there's no way to install this multifunction printer as a FAX.
    So I can't see the FAX on Printers in the control panel of windows.
    I have never got an error message from any computer during the installation process either.
    Does anyone has an idea of what to do here?
    Thanks ahead.

    Thanks for your quick answer, I really appreciate it. But unfortunately, it didn't resolve my problem  
    Actually any of the workstations after complete the installation (with the last version of drivers downloaded just now from hp.com) can't recognize the HP LaserJet Pro 400 Color MFP M475dw, as a fax. I can print and scan over the network, or connecting the printer with a usb cable. I just can't see the icon "HP LaserJet Pro 400 Color MFP M475dw FAX" in Control Panel ---> Devices and Printers.   I did a full installation when I were asked during the installation process... I did then I custom installation and neither of them seems to work to me  
    This is very strange, it never happened to me with any other models of all-in-on (printer/fax/scanner)

  • Epson Stylus CX5400 printing rubbish over the network!!!

    Hi! I am visiting my mom and dad for the holidays and they have an all-in-one Epson Stylus CX 5400 connected to their WinXP computer. Bonjour installed as well.
    I have tried a few times to print some photos from iPhoto. I also tried printing an email from Apple's Mail. Everytime all I got was... nonsense basically. This kind of printout with unreadable characters.
    I thought the lack of drivers for such a device installed in my PB should make no difference but anyway I tried installing them. I was right, the result was the same.
    File sharing takes place without problem. As far as I know the drivers are up to date on both computers. If I connect the CX5400 directly to a PB's USB port it works great, but no otherwise.
    Any thoughts?
    Merry Christmas and happy 2006.
    George...

    Neither the PC nor the printer know what to do with the PostScript your Mac is sending. When the printer is attached directly to the Mac you use the printer's USB driver which speaks the printer's language, but when you send it over the network to the PC, you are using PostScript printing which the PC can't raster, and the printer doesn't understand. I don't think there is a solution here. I doubt there is a PostScript driver for that printer. You could install GhostScript on the PC, but that is very complicated and probably not worth it.

  • Need to send object instances over the network

    I found no other way to implement a switch case to cast objects on both sides to solve my problem.
    Basically I need to send objects over a network protocol based on XML, the object is sent inside XML
    converted in base64, overall encoding of XML is utf-8.
    Let's suppose in my network there are 2 peers connected via socket.
    I have multiple instances of different types on both peers but I want to keep these instances
    synchronized. If something changes on side A, side B must receive that instance and replace
    it in the correct place (just one way, from A to B).
    When I receive such instance on B I want to cast it to it's proper instance
    of it's proper type and I am scratching my head on how could I implement this without some
    sort of unique ID table and switch case.
    If I had 1 instance per type could it be done easily?
    But I need to keep in synch many instances per type.
    Is there any dynamic casting that I can trigger based on some type/instanceID information
    I could send along the object?

    I found no other way to implement a switch case to cast objects on both sides to solve my problem.
    Basically I need to send objects over a network protocol based on XML, the object is sent inside XML
    converted in base64, overall encoding of XML is utf-8.
    Let's suppose in my network there are 2 peers connected via socket.
    I have multiple instances of different types on both peers but I want to keep these instances
    synchronized. If something changes on side A, side B must receive that instance and replace
    it in the correct place (just one way, from A to B).
    When I receive such instance on B I want to cast it to it's proper instance
    of it's proper type and I am scratching my head on how could I implement this without some
    sort of unique ID table and switch case.
    If I had 1 instance per type could it be done easily?
    But I need to keep in synch many instances per type.
    Is there any dynamic casting that I can trigger based on some type/instanceID information
    I could send along the object?

  • App imitates sending out a virus over the network

    The last time I ran the Classic App called "Farallon Ping" which came with my old Farallon NC I bought years ago was back in 2003 or 2004 and I was told by IS of the University I was attending not to run it again as the app makes it appear to be sending out viruses over the network. The app is useful as it tells me my IP address and the IP address of every computer in my domain and offers many other features some of which that are lacking in the built in OSX utilities.
    I am at a much larger University these days and I was wanting to run this app for the features but not sure if I should.
    Is this post appropriate for this group and if so what do you say?
    Thanks

    Know nothing about Farallon Ping. Would MacPing at http://74.125.93.104/translate_c?hl=en&sl=nl&u=http://dartware.com/downloads/leg acy.html do the same thing?
     Cheers, Tom

  • Sending Video over the wireless network

    I am considering capturing images from a IEEE 1394 camera and sending it over the Wireless network to another computer.  The reason we want to do that is to make the
    camera device light and portable by connecting it to a portable tablet computer.
    What kind of protocol is the best way to transfer the image. The TCP or UDP in labview convert data into string before the transmission which are very inefficient. I just want to streaming the raw image data, maybe with some protocol overhead.  Did National Instrument has any package to do that or any other software packages available?
    There might be another solution is to use the Ethernet cameras instead of 1394 cameras.
    Would it be possible for the Labview application on a remote desktop computer to acquire the Ethernet camera over a WiFi wireless connnetction in between ?
    Thanks
    Cindy

    Hello Cindy,
    If you want to transfer data across a
    network, TCP would be the most efficient method (wireless is typically not as
    successful as Ethernet due to the overhead).  There is actually a very useful knowledgebase
    document that discusses the various methods used to transfer image data across
    a network.  If you go to our main site http://www.ni.com and search using the keywords “Images
    Over Network”, the first link is entitled Streaming
    IMAQ Images Over a Network (or Internet) which gives brief descriptions if
    you choose to use TCP/IP, Datasocket, LabVIEW web server, or ActiveX.  Another very informative document results in
    that same search and is titled Transfer Images Over the Network
    which actually gives examples
    illustrating different ways to send images.  I hope this helps.  Please let us know if you would like further
    clarification or assistance regarding this issue.Vu D

  • Sending Connection Object over the Network using RMI

    Hi,
    How can a Connection object be sent over the network and run on another JVM. I need to hold connection object to execute processes one after other, that require Oracle connection without ever connecting again. I do not have J2EE container or webserver setup to hold connection/connectionpool,but need to run the process on command line. I am using RMI infrastructure to pass parameters/return values but connection object is not serializable and connot be marshalled and failing. Please explain, if there is another way using JDK 1.4
    Sudheer

    I think that what you want to do is connect to the database on the RMI server object, then use the server object from your remote clients to execute the processes you require to rrun.

  • Sending Connection object over the network

    Hi,
    How can a Connection object be sent over the network and run on another JVM. I need to hold connection object to execute processes one after other, that require Oracle connection without ever connecting again. I do not have J2EE container or webserver setup to hold connection/connectionpool,but need to run the process on command line. I am using RMI infrastructure to pass parameters/return values but connection object is not serializable and cannot be marshalled and failing. Please explain, if there is another way using JDK 1.4
    Sudheer

    I don't believe this is possible. A connection object has a number of associated structures on the operating system, which generally makes it impossible to move. From a fundamental networking level, you also cannot, in general, cause a connection to machine1 to start communicating with machine2-- that would introduce all manner of security problems.
    Why don't you want to just create another connection on the other machine?
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • HP Laserjet M1132 MFP is too slow over the network!

    Hi,
    My HP Laserjet M1132 MFP is too slow over the network!
    I have connect the printer to a windows XP 32bit SP3 using UBS port. The printer works fine on the local computer but when sharing it over the network it works too slow, for example with print test page it takes about 45 seconds to print and for other documents it takes much longer time.
    I have installed the latest driver form HP website and upgrade the firmware it the latest version.
    It happens on other Windows XP machines as well.
    I connected the printer to my laptop (Windows 7 64bit) and it works fine (No delays over the network) and it seems that this problem have some relations with the windows XP Driver.
    I have used local port trick on remote machines (instead of regular method) like this:
    ''add a local printer;
    'new port'
    'localport'
    \\XPcomputer\HPPrinterName as port name
    but still nothing!
    There is nothing wrong with the network, we use to use a Samsung printer on the same machines over the network with no problem.
    I Really appreciate your HELP!
    This question was solved.
    View Solution.

    BEHZAD_T, how is the printer connected to the network (wireless or Ethernet)? If it is slow wirelessly, I would suggest trying to connect the printer to your router with the Ethernet cord and install it to the networked computer that way.
    Another question is, relatively speaking, how close to your router are the Samsung printer and the HP printer? Depending on the distance (and what stands between the devices) there can be a lag between sending a print job and it being received by the printer.
    Let me know!

  • Pinging a printer to see if it works over the network

    I've been printing from a Windows 7 computer to a PSC C6180 over a wireless network.  All of a sudden it stopped printing.  I don't if a power surge or something blew some stuff out (the fax part is already gone) or if it is something else. 
    I removed the printer and removed the installed software in order to put it back in its "initial state." 
    Before I removed the software, I tried to add a network printer to see if that would do it.   At the point in the process where it looks for printers, it didn't find it.  It makes me wonder if it will work over the network at all, but I do note the blue 802.11g LED is lit.
    Before I reinstall the software (AIO_CDA_FSW_Full_Win_WW.130_140.exe is what I have) I want to ping the printer and see if the computer can see it.  What's the ping address?

    Hello ErnieLane,
    Please follow steps 1-4 described in Access the Embedded Web Server to print a configuration page, it will contain the current IP address (if any).
    Hope this will help.
    Regards,
    AndOne
    Say "Thanks" by clicking the Kudos Star in the post that helped you.
    Please mark the post that solves your problem as "Accepted Solution"
    (Although I am employed by HP, I am speaking for myself and not for HP)

  • Can object transfer over the network without serialization?

    Hi all,
    Can we send the objects over the network (from clent to server)
    without seraializing it?
    Thanks in advance

    Yes. By sending its values by any other means, like as XML.

  • No JMS over the network

    hello,
    Im learning JMS and trying the examples from the tutorial. Both my SDK's are version 1.4.
    At home, I have a Linux machine directly connected to a win-XP machine. Im trying to connect the two machines as in the example "Running JMS Client Programs on Multiple Systems" I do exactly what the turorial states. I check, as recommended, that the JmsFactory does exist.
    What happens is somewhat dissapointing: when i issue the command "run SimpleProducer MyQueue queue 3", instead of messages get send over the network they end up in the own local queue at the side of the SimpleProducer. Both on the linux as on the win machine the same happens. I used both the IP-address and the netbios name of the remote machine in "ant add-remote-factory -Dsys=sys-name". The effect is the same.
    Anyone an idea what is wrong??
    Thank i.a.

    hi!
    i went to bed frustrated, turned on my computer and now this comes up:
    I try to lookup the connection factory with this code:
    try {
    connectionFactory = (ConnectionFactory)
    jndiContext.lookup("EarthQueueConnectionFactory");
    if (destType.equals("queue")) {
    dest = (Queue) jndiContext.lookup(destName);
    } else if (destType.equals("topic")) {
    dest = (Topic) jndiContext.lookup(destName);
    } else {
    throw new Exception("Invalid destination type" +
    "; must be queue or topic");
    } catch (Exception e) {
    System.out.println("JNDI API lookup failed: " +
    e.toString());
    System.exit(1);
    This is the error it returns:
    C:\j2sdkee1.4\doc\tutorial\examples\jms\simple>run SimpleProducer MyQueue queue 1
    Destination name is MyQueue, type is queue
    18-feb-2003 11:35:52 com.sun.jms.ConnectionFactoryImpl establishRemoteReferences
    SEVERE: ConnectionFactoryImpl: Failed to lookup or connect to JMS service because: org.omg.CORBA.OBJECT_N
    OT_EXIST: vmcid: SUN minor code: 202 completed: No
    18-feb-2003 11:35:52 com.sun.jms.ConnectionFactoryImpl establishRemoteReferences
    SEVERE: ConnectionFactoryImpl: Failed to lookup or connect to JMS service because: org.omg.CORBA.OBJECT_N
    OT_EXIST: vmcid: SUN minor code: 202 completed: No
    Exception in thread "main" java.lang.NullPointerException
    at com.sun.jms.client.ConnectionImpl.invokeRemoteCreateConnection(ConnectionImpl.java:161)
    at com.sun.jms.ConnectionFactoryImpl.createConnection(ConnectionFactoryImpl.java:314)
    at com.sun.jms.ConnectionFactoryImpl.createXAConnection(ConnectionFactoryImpl.java:468)
    at com.sun.jms.ConnectionFactoryImpl.createXAConnection(ConnectionFactoryImpl.java:444)
    at com.sun.jms.connector.ra.JMSConnectionFactoryAdapter.createConnection(JMSConnectionFactoryAdap
    ter.java:129)
    at SimpleProducer.main(Unknown Source)
    MyQueue exists and my j2eeadmin -listJmsFactory looks like this:
    JmsFactory
    < Connector Resource : jms/TopicConnectionFactory, jmsra.rar, , , javax.jms.TopicConnectionFactory
    Properties: NONE >
    < Connector Resource : jms/QueueConnectionFactory, jmsra.rar, , , javax.jms.QueueConnectionFactory
    Properties: NONE >
    < Connector Resource : EarthQueueConnectionFactory, jmsra.rar, , , javax.jms.QueueConnectionFactory
    Properties: >
    I have really no clue what is wrong. Can someone help me please????

Maybe you are looking for

  • Can a family member trade-in?

    Can I have my brother trade a few games for me? I can't make it to BBY this week for the 50% bonus. I'll give him my rewards card for the extra 10% GCU.

  • Javascript does not work in Adobe 9 Reader

    I have created a Parent PDF Index with attachments. Next to each document name, I have 3 icons (PDF, Print and Email icons). The PDF Icon has a basic link: "Go to page in another document" The Print Icon has the "Go to page in another document" link

  • Where has Menu Item : "Edit Links..." within MSP (Standard or Professional) 2007 gone to in version 2010 and/ or 2013 ?

    Hi folks, Can someone please tell me where I can find the "Links..." menu item in version 2010 and ver. 2013 that is under the EDIT menu, up until MS Project (Standard or Professiona) version 2007 ? Just as a refresher, the Links dialog window has an

  • No Signal from appletv.

    I've already  I. Restored AppleTV via iMac 2. rebooted using the remote but still no signal.  Cabling and TV working fine.

  • Generic Data Access For All Class

    Hello I am doing one experiment on Data Access. In traditional system We have to write each Insert, Update, Delete code in data access for each table. My City Table Class: public class TbCitiesModel string _result; int _cityID; int _countryID; string