Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have C# server implemented with sockets in this way:
I have a listener:
C#
TcpListener listener = new TcpListener(IPAddress.Any, 33333);
listener.Start();


I created a new client every time a client connects
C#
TcpClient client = listener.AcceptTcpClient();


And a BinaryReader and BinaryWriter:
C#
NetworkStream stream = client.GetStream();
w = new BinaryWriter(stream);
r = new BinaryReader(stream);


If I want to write or read something to connected client i am using:
C#
w.Write(MESSAGE);//for writing
msg=r.ReadString();//for reading something that client sends


The problem:
How can I create a java program to comunicate with this server, I only managed to connect to the server(create the socket) but i didn't find anything on google about how to send and receive messages, I tried different ways but it didn't write or read anything. Any suggestions? or a very simple java program would be just enough. Thanks

Regards,
Sas Gabriel
Posted
Updated 14-Dec-11 21:55pm
v3
Comments
Nagy Vilmos 15-Dec-11 3:55am    
Added some formatting

Use Google to find source code for sockets in Java. Once you have created the socket the language has nothing to do with it. The only issue is that the data you transfer between client and server must be in a form that both ends agree and understand. Simple ASCII bytes is probably the best form, with maybe a header byte giving the length of the message.
 
Share this answer
 
Comments
Nagy Vilmos 15-Dec-11 3:57am    
Excellent answer Senor Ricardo!
Further to Richard's excellent answer, look here[^] for some easy examples of writing a Java TCP/IP client.
 
Share this answer
 
Comments
Richard MacCutchan 15-Dec-11 4:10am    
Very useful links, filed for future reference.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900