• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java program works in Windows but not in Mac

 
abacaba obocobo
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I have done a program that send a screen capture over a socket. Well, it works if I take the screen capture in the mac and send it to the windows pc(7, xp doest work), but if i want to take the screen capture in windows and send it to the mac it just send part of the file... Here is the client


And The server

 
Maxim Karvonen
Ranch Hand
Posts: 121
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you clarify, which exaclty part of the file is sent? It is a first part or tail part or some other completely unrelated part?

Main problem with your code is mixing readers and byte input on a same stream and not using a buffered streams consistently. In server code you wraps socket.getInputStream into a buffered writer. That buffered writer may also consume part of the file into it's internal buffer (it is called buffered for a reason). And you server.client() method miss that initial file fragment already put in a buffer.

One of possible fixes. Use DataInputStream/DataOutputStream. Read/write commands using readUtf/writeUtf methods. Write a file length before a file content (so you know how many bytes to read on a server side). Actual format for a client->server screen command will be something like "sceenon <file-length> <file-content>". And stick to only one stream instance across your code. If you have created DataInputStream for a socket.getInputStream() then use only that DataInputStream to communicate with the other side.
 
Ivan Jozsef Balazs
Rancher
Posts: 981
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This builds a reader (using the platform default encoding - can you tell what it is?) around the input stream.
If the input stream happens to be a binary stream you can not assume its being a character stream using the platform default encoding!


Also in "copyScreen" you break the loop if less than 1024 bytes were read. Actually why?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic