I am trying to send json messages to a specific ip and port using tcp socket connections. The code seems to work with the initial connection and message submission but when checking the destination server, I do not find the messages. I have a .NET version that runs as well and for some reason trying to send the exact same message works fine. I tried to use wireshark to capture the packet and connection but it seems there is no packets being set at all.
wireshark capture:
The code in java :
try
{
clientSocket = new Socket(ipaddress, portnumber);
outStreamSplunk = new PrintWriter(clientSocket.getOutputStream(), true);
outStreamSplunk.flush();
clientSocket.setKeepAlive(true);
clientSocket.setSoTimeout(1000);
outStreamSplunk.println(post + "\n");
System.out.println("SENT MESSAGE: " + post);
clientSocket.close();
}
catch (Exception exc)
{
modifiedSentence = "";
}
and the code in .NET that works:
ip = "xxx.xxx.x.xxx"
port = xxxx
Dim ips As String = Dns.GetHostEntry(ip).AddressList(0).ToString()
_GLOIP = IPAddress.Parse(ips)
_port = port
'initiate the client and get the stream to use
myTcp = initiate()
netStream = myTcp.GetStream()
Try
If netStream.CanWrite Then
If Not text.EndsWith(vbCr & vbLf) Then
text += Environment.NewLine
End If
Dim sendBytes As Byte() = Encoding.UTF8.GetBytes(text)
netStream.Write(sendBytes, 0, sendBytes.Length)
Else
err = "cannot write to the stream"
End If
Catch ex As Exception
appLogs.constructLog(err & vbNewLine & ex.Message.ToString, True, True)
Exit Sub
End Try
EDIT:
I tried another server as I thought it may be my machine and since the .NET script runs on another machine. Turns out the TCP connection works fine but not sure how to interpret the response:
I dont see any errors so perhaps its a problem with the destination server. The only other difference between the .NET version and java version is that the.NET version is writing into byte array. This has me stumped. But if I don't find resolution I will need to do it the hard way and use the .NET version and transfer message somehow from main java code to the .NEt version.


exc.printStackTrace().ipaddressorportnumberis invalid, so that no connection is even attempted (since Wireshark would see the connection attempt).