Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Sending 2D (multi-dimensional) int pointer arrays via Winsock socket (in C)

Avatar of tnndesign
tnndesign asked on
Programming Languages-OtherC.NET Programming
2 Comments1 Solution1714 ViewsLast Modified:
I have developed a custom Winsock-based library in C for sending data to/from a socket connection between a server and client socket.

My custom library includes functions to transmit and receive single-dimensional (1D) integer-type pointer arrays. It works like this:

int socketlib_Send_int_Mx1(SOCKET targetSocket, int *Mx1, int m)
	// Send array size
	if(socketlib_Send(targetSocket, (char*)&m, sizeof(m)) < 1)
		return 0;

	// Send array data
	if(socketlib_Send(targetSocket, (char*)Mx1, sizeof(int)*m) < 1)
		return 0;

	// Successful transmission
	return 1;

- Assume I have an array already malloc'd in memory:
testArray[0] = 10;
testArray[1] = 20;

- Array is transmitted like this (dimension count is also transmitted - see above function):
// Transmit data to server
socketlib_Send_int_Mx1(clientSocket, testArray, arrLen);

Now I am wanting to transmit a multi-dimensional array ie.
int **myarray;
// Code to malloc both dimensions (not shown)
myArray[0][0] = 1;
myArray[0][1] = 2;
myArray[1][0] = 3;
myArray[1][0] = 4;

How would I then go about transmitting the 2D array over sockets? I just am having trouble figuring it out - I know I could simply loop through all the dimensions and transmit as single ints..but want to transmit it all in one go, like the 1D array.

Suggestions would be greatly appreciated! Many thanks in advance. socketlib.c
(See attached file)
Avatar of Infinity08
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answers