如何通过套接字 PHP 将文件传输到 C#


How to transfer a file by socket PHP to C#

嗨,经过大量研究,我没有找到解决我的情况的方法

我有一个 C# 套接字服务器,我的服务器上正在运行,我需要通过套接字从我的 PHP 网站将文件传输到它。

我现在有什么?

PHP部分:

    $file = array('file' => Input::file('file'));
    $fp = stream_socket_client("tcp://localhost:9192", $error_number, $error_string);
    if ( !$fp ) {
        echo "$error_number ($error_string)'n";
    } else {
        fwrite($fp, $file['file']);    
    }
    fclose($fp);

C# 套接字服务器:

        String content = String.Empty;
        // Retrieve the state object and the handler socket
        // from the asynchronous state object.
        StateObject state = (StateObject)ar.AsyncState;
        Socket handler = state.workSocket;
        // Read data from the client socket. 
        int bytesRead = handler.EndReceive(ar);
        if (bytesRead > 0)
        {
            // There  might be more data, so store the data received so far.
            state.sb.Append(Encoding.ASCII.GetString(
                state.buffer, 0, bytesRead));
            // Check for end-of-file tag. If it is not there, read 
            // more data.
            content = state.sb.ToString();
            if (content.IndexOf("<EOF>") > -1)
            {
                // All the data has been read from the 
                // client. Display it on the console.
                Console.WriteLine("Read {0} bytes from socket. 'n Data : {1}",
                    content.Length, content);
                // Echo the data back to the client.
                Send(handler, content);
            }
            else
            {
                // Not all data received. Get more.
                handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
                new AsyncCallback(ReadCallback), state);
            }
        }

当我尝试建立连接时,C# 立即拒绝它我做错了什么?

我在PHP部分使用Laravel 5。

我在这个问题中找到了一个解决方案:

如何通过使用套接字发送的TCP接收文件。文件发送方法

很抱歉浪费您的时间:)