Socket communication between a Java and/or C ++ programs (ready-made programs)

Source: Internet
Author: User
Java/C ++ socket class

If you need to do socket communication between a Java and/or C ++ programs, you 've come to the right place. I 've developed a fairly basic class that can be used to communicate between Java applications and C ++ programs via a socket connection. there are client and server classes for both Java and C ++, so you can use these classes for communication between the same language or between languages.

The classes below have been tested and seem to work. you must of course balance your sends and ES otherwise it will stall. you will have to determine whether the byte order needs to be reversed between your client and server. it appears that byte order will need to reversed if one side is Java and the other side is C ++. if both sides are the same language, you should be okay without reversing them.

Efficiency isn' t the best. I worked some time to get the classes to perform as well as they do. sending and processing ing of bytes is fairly fast, but other types require the Java side to convert the data array to an array of bytes. this was necessary in order to get the data to be sent in bigger, more efficient blocks. I suspect the conversion cocould be done faster than my stream technique, but I have not pursued it.

The fastest method I found to send data was using the datatemethods. be careful, since this is not a guaranteed delivery form of communication, packets can and do get lost in transit. you'll need to do some sort of communication via the normal send and receive routines to provide resending of missing packets.

For more details about the implementation, there is a section in the my thesis project paper.

A lot of the C code for the socket routines I lifted from the excellent Tutorial: beej's Guide to network programming. for a starting point on the Java code, I used the book: Java: how to program, deitel & deitel.

Client. Java Socket Client written in Java
Server. Java Socket server written in Java
Client. cpp Socket Client written in C ++
Client. h Header file for the c ++ Client
Server. cpp Socket server written in C ++
Server. h Header file for the c ++ Server
Makefile Makefile for all for the above and the test programs
Server_test.cpp Simple Test Program of the C ++ Server
Client_test.cpp Simple Test Program of the C ++ Client
Java_server_test.java Simple Test Program of the Java Server
Java_client_test.java Simple Test Program of the Java client
Socket.tar All the above in a convenient tar file
Swarm_monitor.tar A example using the socket library to measure performance on an MPI network.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.