How to send a binary stream from Java-client to C#-server via Tcp?

  • Context: Java 
  • Thread starter Thread starter user366312
  • Start date Start date
  • Tags Tags
    Binary Stream
Click For Summary
SUMMARY

This discussion focuses on the challenges of sending a binary stream from a Java client to a C# server via TCP. The provided C# code utilizes TcpClient and NetworkStream, while the Java code employs Socket and DataInputStream. The main issue identified is that the C# server does not receive the string sent by the Java client, likely due to differences in how data is serialized and deserialized between the two languages. The recommended solution is to use ZeroMQ for cross-language communication, which simplifies the process and adheres to best practices for microservices.

PREREQUISITES
  • Understanding of TCP/IP networking concepts
  • Familiarity with C# TcpClient and NetworkStream
  • Knowledge of Java Socket and DataInputStream
  • Basic understanding of serialization and data encoding
NEXT STEPS
  • Research ZeroMQ and its request-reply pattern for cross-language communication
  • Learn about raw byte reading and writing in both C# and Java
  • Explore serialization techniques in C# and Java to ensure compatibility
  • Investigate network debugging tools to monitor TCP connections and data flow
USEFUL FOR

Software developers working on cross-platform applications, network engineers, and anyone involved in microservices architecture who needs to facilitate communication between Java and C# components.

  • #31
PeterDonis said:
Why would he want to do that? He's not trying to transfer files.
Transferring a bit stream has the same inherent problems as transferring binary files. It is not dead easy - FTP has gone through several revisions.
 
  • Like
Likes   Reactions: jedishrfu
Technology news on Phys.org
  • #32
user366312 said:
Which console? C# or Java?

Both the C# will show that it works and the Java one will show something else that may be key to your problem.
 
  • #33
jedishrfu said:
Both the C# will show that it works and the Java one will show something else that may be key to your problem.

I have solved the problem. Never mind.

I thank all of you for your time and effort.
 
  • #34
That's great!

So what was the problem?
 
  • #35
jedishrfu said:
That's great!

So what was the problem?

There was difference in r/w data format.

I am now using raw data format on both ends. I am using byte arrays.
 
  • #36
Svein said:
Transferring a bit stream has the same inherent problems as transferring binary files

It has some of the same inherent problems, yes. But those problems are lower level than the application/protocol level. At the application/protocol level, FTP is specialized for transferring files (which don't have to be binary, FTP has a text mode as well--not that I would recommend using it, but it has one :wink:). And actually it's not a very good protocol for transferring files, since it requires two TCP connections instead of one and coordination between the two connections (control and data) is clunky.
 
  • #37
user366312 said:
There was difference in r/w data format.

I am now using raw data format on both ends. I am using bye arrays.

If this work gets more involved then you might want to consider zeromq.

Its very popular for communications between disparate programs in a microservices environment, has several multi-program architectures depending on the problem, and you get extra capability that might prove useful in the future.
 
  • #38
jedishrfu said:
If this work gets more involved then you might want to consider zeromq.

Its very popular for communications between disparate programs in a microservices environment, has several multi-program architectures depending on the problem, and you get extra capability that might prove useful in the future.

ZeroMQ is good for professional solutions. I doing a semester project.
 
  • #39
user366312 said:
ZeroMQ is good for professional solutions. I doing a semester project.

But you could put it on your resume sometimes these little things make a big difference.
 
  • #40
jedishrfu said:
But you could put it on your resume sometimes these little things make a big difference.
Okay. Thanks for the advice. I will look into that.
 

Similar threads

  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 3 ·
Replies
3
Views
13K