메시지를 받고 확인 응답을 보내야하는 TCP 수신기 (서버)를 쓰고 있습니다. 아주 기본적인 것들. 말 그대로 MSDN을 포함한 수십 가지의 예제가 있습니다. 여기에서 많은 코드를 복사했습니다. 아무런 문제없이 메시지를받을 수 있습니다. 문제는 응답을 다시 보내려고 할 때 발생합니다. 송신 클라이언트 (Corepoint의 HL7 엔진은) 다음과 같은 오류를보고합니다확인/응답을 보내기 전에 TCP Listener 연결을 닫습니다.
The connection was closed before a response was received
내가 (MSDN에서 복사 한 코드를 사용하여 작성) 내 자신의 TCP 전송 테스트 애플 리케이션 내 서비스를 테스트하고 그것을 작동합니다. 그러나 Corepoint에서 메시지를 받으면 응답이 되돌아 가지 않습니다.
아래 코드는 제 코드입니다. 누구나 NetworkStream.Write 메서드가 실제로 데이터를 보내지 않는 이유 (또는 클라이언트가 데이터를받지 못하는 이유)를 알고 있습니까? 내 문제와 비슷한 다른 게시물에서 발견 한 모든 아이디어를 시도했지만 아무 것도 작동하지 않습니다. Corepoint의 구성이 잘못되었거나 잘못 되었습니까?
Sub Main()
listenThread.Start()
End Sub
Private serverSocket As TcpListener
Dim listenThread As New Thread(New ThreadStart(AddressOf ListenForClients))
Private Sub ListenForClients()
Dim port As Int32 = '(pick a port #)
Dim localIP As IPAddress = 'enter your IP
serverSocket = New TcpListener(localIP, port)
serverSocket.Start()
While True 'blocks until a client has connected to the server
Dim client As TcpClient
If serverSocket.Pending Then
client = serverSocket.AcceptTcpClient
'tried these 2 settings with no effect
'client.NoDelay = True
client.Client.NoDelay = True
ProcessIncomingMessageSocketTCPClient(client) 'I was doing this in a separate thread but temporarily kept it on this thread to eliminate threading as the possible cause (but no luck)
client.Close()
Else
Threading.Thread.Sleep(1000) 'wait 1 second and poll again
End If
End While
End Sub
Private Sub ProcessIncomingMessageSocketTCPClient(ByRef objClient As TcpClient)
Dim strMessageText As String
Dim clientStream As NetworkStream
Dim msgBuffer(4096) As Byte
Dim numberOfBytesRead As Integer
Dim strChunk As String
Dim strCompleteMessage As New Text.StringBuilder
Dim sendBytes As Byte()
clientStream = objClient.GetStream()
Do
numberOfBytesRead = clientStream.Read(msgBuffer, 0, msgBuffer.Length)
strChunk = Encoding.ASCII.GetString(msgBuffer, 0, numberOfBytesRead)
strCompleteMessage.AppendFormat("{0}", strChunk)
Loop While clientStream.DataAvailable
strMessageText = strCompleteMessage.ToString
sendBytes = Encoding.ASCII.GetBytes("I received a message from you")
clientStream.Write(sendBytes, 0, sendBytes.Length)
objClient.Close() 'tried it with and without this line
End Sub
폴링 루프에서 클라이언트를 닫지 않으려 고 시도 했습니까? 일반적으로이 동작은 실제로 연결에서 데이터를 가져 오기 전에 의도적으로 연결을 종료했거나 (또는 프로그램을 종료했기 때문입니다.) – derelict
예, 시도했습니다. 아무런 효과가 없었다. –