客户端从服务器向客户端发送大字符串(BASE64映像)

时间:2015-12-10 09:28:31

标签: java c# sockets server

我在客户端和服务器之间通过套接字进行通信时遇到问题。 Java服务器和C#中的客户端。当我将一个String Base64类型的图像发送到我的C#客户端时,由于字符串的大小,我的程序崩溃了。

void ecouteur(string commande) {

        try {
            IPEndPoint   ip = new IPEndPoint (IPAddress.Parse ("127.0.0.1"), 1234);
            System.Net.Sockets.Socket sock = new System.Net.Sockets.Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            sock.Connect (ip);
            byte[] data = new byte[2024];
            int receivedDataLength = sock.Receive (data);
            String temp = Base64Decode( Encoding.ASCII.GetString (data, 0, receivedDataLength));



            sock.Shutdown (SocketShutdown.Both);
            sock.Close ();

        } catch (SocketException e1) {

            Console.WriteLine ("****Unable to connect to server.****\n" + e1);
            //sock.Shutdown (SocketShutdown.Both);
            sock.Close ();
        }
}

0 个答案:

没有答案