Please Varify my Method .
I am not getting expected output ..
Code:int Amount=500; send(newSocket,Amount,4,0); close(welcomeSocket); recv(clientSocket,Amount,4,0); // Amount= ntohl(Amount); printf("Data received: %d",atoi(Amount[0]));
Please Varify my Method .
I am not getting expected output ..
Code:int Amount=500; send(newSocket,Amount,4,0); close(welcomeSocket); recv(clientSocket,Amount,4,0); // Amount= ntohl(Amount); printf("Data received: %d",atoi(Amount[0]));
Other have classes, we are class
sudhakar@sudhakar-Aspire-E1-570:~/Desktop$ ./Receiver -m 0 -p 5000 -z 256 -P t
*** Error in `./Receiver': munmap_chunk(): invalid pointer: 0x00007fff7725f2a0 ***
Aborted (core dumped)
Error is coming after applying above code
The error is probably in code unrelated to what you have shown. There is nothing in the code WoodSTokk provided that would cause a pointer related problem.
Incidentally, the original code as you showed it here would not have even compiled.
sockfd = socket(AF_INET, SOCK_STREAM, 0);
n = write(sockfd,buffer,packet_size);
I used this socket to send traffic .Is there any problem with using same socket for another communication ,What I am doing righ now else I should create a separate socket
Wait what? I haven't really played with the sys/socket.h stuff but I have done some socket programming in delphi. A RAT tool that I used in class Just speaking from memory. Usually you'll create a socket to either connect to a host ( yourself or any other address ) , this socket cannot be used for hosting a server ( bare with me ) - You'll get an error if you try to bind a socket that is already connected to a server so usually you either destroy ( a delphi destructor ) the socket that is currently in use and then use bind to create a server. I'm not sure whether close(socket);
I wouldn't play around with sockets, read up on them first they are far from easy. I didn't do much reading on this because well I have things to do and if this really means anything to you I hope you'll research it yourself. If you really want to get into sockets take a look at threading first. Especially if your going to be writing a server program ^^. They are huge fun but can also cause all sorts of trouble.
I suspect the close function only terminates the connection made to/with the socket. So I suppose if you close the socket using it for another operation should be fine (assuming you thereafter use bind/connect for the right situation XD ) .
A reference to the close() function : The GNU C Library: Closing a Socket
Last edited by RagingGrim; 12-24-2014 at 09:32 AM.