Commit 3e7e619192f88253f441f9c2d538eeb6d9e72cb6

Authored by Imanol-Mikel Barba Sabariego
1 parent ae3aa1ff

git-svn-id: svn://imanolbarba.net/PAD@59 c2ee353e-ed0d-4329-bf56-03aec153487f

JChatServerV2/src/pad/prac2/MySocket.java
@@ -7,6 +7,7 @@ import java.io.OutputStream; @@ -7,6 +7,7 @@ import java.io.OutputStream;
7 import java.net.InetSocketAddress; 7 import java.net.InetSocketAddress;
8 import java.net.Socket; 8 import java.net.Socket;
9 import java.net.SocketAddress; 9 import java.net.SocketAddress;
  10 +import java.nio.charset.Charset;
10 11
11 public class MySocket extends Socket 12 public class MySocket extends Socket
12 { 13 {
@@ -37,7 +38,7 @@ public class MySocket extends Socket @@ -37,7 +38,7 @@ public class MySocket extends Socket
37 try 38 try
38 { 39 {
39 output = super.getOutputStream(); 40 output = super.getOutputStream();
40 - input = new BufferedReader(new InputStreamReader(super.getInputStream(),"UTF-8")); 41 + input = new BufferedReader(new InputStreamReader(super.getInputStream()));
41 } 42 }
42 catch(IOException ioExc) 43 catch(IOException ioExc)
43 { 44 {
@@ -67,7 +68,7 @@ public class MySocket extends Socket @@ -67,7 +68,7 @@ public class MySocket extends Socket
67 68
68 public void write(String str) throws IOException 69 public void write(String str) throws IOException
69 { 70 {
70 - output.write(str.getBytes()); 71 + output.write(str.getBytes("UTF-8"));
71 } 72 }
72 73
73 public String read(int bytes) 74 public String read(int bytes)
@@ -76,7 +77,8 @@ public class MySocket extends Socket @@ -76,7 +77,8 @@ public class MySocket extends Socket
76 try 77 try
77 { 78 {
78 input.read(buffer, 0, bytes); 79 input.read(buffer, 0, bytes);
79 - return new String(buffer); 80 + byte[] bytesRead = new String(buffer).getBytes("UTF-8"); //Cosas del Unicode, por culpa del **** Java
  81 + return new String(bytesRead,"UTF-8");
80 } 82 }
81 catch(IOException ioExc) 83 catch(IOException ioExc)
82 { 84 {