473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

socket between java client and c++ server

Hi,
don't know if it is the place to ask this question

I have a c++ server and a java client communicate via socket

in Java client
// create a client socket
Socket clientSocket = new Socket("localhost", 27015);
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(),
true);

String userInput = "amsg";
System.out.println("send to server:" + userInput.length() + " :" +
userInput);
out.println(userInput);

in c++ server
// code to starup the connection
int recvbuflen = 255;
char recvbuf[255];
int iResult = recv(ClientSocket, recvbuf, recvbuflen, 0);
cout<<"iResult = "<<iResult<<endl;
the msg sendout in java client "amsg" is 4, while, in the c++ server,
it says the msg length = 6.
it always +2.
when I send the msg from a java client to a java server via socket,
there is no such problem

any suggestion. thanks

Dec 14 '06 #1
2 6469


On Dec 14, 10:57 pm, "happyvalley" <nittanymount...@gmail.comwrote:
Hi,
don't know if it is the place to ask this question

I have a c++ server and a java client communicate via socket

in Java client
// create a client socket
Socket clientSocket = new Socket("localhost", 27015);
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(),
true);

String userInput = "amsg";
System.out.println("send to server:" + userInput.length() + " :" +
userInput);
out.println(userInput);

in c++ server
// code to starup the connection
int recvbuflen = 255;
char recvbuf[255];
int iResult = recv(ClientSocket, recvbuf, recvbuflen, 0);
cout<<"iResult = "<<iResult<<endl;

the msg sendout in java client "amsg" is 4, while, in the c++ server,
it says the msg length = 6.
it always +2.
when I send the msg from a java client to a java server via socket,
there is no such problem

any suggestion. thanks
Its sending the \eol \cr chars as well... (or in Java's speak '\n'
- because you used out.println(...) instead of out.print() )

Dec 14 '06 #2

andrewmcdonagh wrote:
On Dec 14, 10:57 pm, "happyvalley" <nittanymount...@gmail.comwrote:
Hi,
don't know if it is the place to ask this question

I have a c++ server and a java client communicate via socket

in Java client
// create a client socket
Socket clientSocket = new Socket("localhost", 27015);
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(),
true);

String userInput = "amsg";
System.out.println("send to server:" + userInput.length() + " :" +
userInput);
out.println(userInput);

in c++ server
// code to starup the connection
int recvbuflen = 255;
char recvbuf[255];
int iResult = recv(ClientSocket, recvbuf, recvbuflen, 0);
cout<<"iResult = "<<iResult<<endl;

the msg sendout in java client "amsg" is 4, while, in the c++ server,
it says the msg length = 6.
it always +2.
when I send the msg from a java client to a java server via socket,
there is no such problem

any suggestion. thanks

Its sending the \eol \cr chars as well... (or in Java's speak '\n'
- because you used out.println(...) instead of out.print() )
thanks a lot, seems print() doesnot work, should be write()

Dec 15 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Al Wilkerson | last post by:
Is anyone aware of any special things to remember when sending Objects back in forth between Client and Sever, other than every readObject() should have a writeObject() and vice versa ? Does the...
1
by: Krzysztof Pa¼ | last post by:
Hi, I want to make simple client in phyton, which would be able to communicate with Java server using SSL sockets. There is the Java clients, which is doing this - so I'm pretty sure, that Java...
4
by: zbcong | last post by:
Hello: I write a multithread c# socket server,it is a winform application,there is a richtextbox control and button,when the button is click,the server begin to listen the socket port,waiting for a...
2
by: zhebincong | last post by:
Hello: I write a multithread c# socket server,it is a winform application,there is a richtextbox control and button,when the button is click,the server begin to listen the socket port,waiting...
3
by: spasavvas | last post by:
Hi I am trying to create a server – client model where client send a file and when server receive the file send back an ack msg. My code is: import java.net.*; import java.io.*; class...
3
by: madsornomads | last post by:
Hi all, I have a problem with reading from a Java server after I have written to it - it just hangs. It works fine if I just write to the server and not try to write. I have read the HOWTO on...
0
by: kuguy | last post by:
Hi all, I'm new to the forums, so I hope this isn't in the wrong place... I have that "Software caused connection abort: socket write error" exception error that i've never meet before. ...
3
by: TsanChung | last post by:
I want to make a java TCP socket client to communicate with a TCP server socket on linux. Are there some sample C unix server and java client socket programs available? The Richard Stevens'...
2
by: rayoflight | last post by:
This is how my test program works. Server will encrypt some text and sends it over to the client. The client will then decrypts it. However I have some problem decrypting it. When I play...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.