Error with accept();

This is a discussion on Error with accept(); within the Networking/Device Communication forums, part of the General Programming Boards category; "implements the msdn"? MSDN is not a library or a verison of libc++, it's just a website with lots of ...

  1. #16
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    "implements the msdn"? MSDN is not a library or a verison of libc++, it's just a website with lots of information. it stands for microsoft developer network. VC7 has an implementaiton of Win32API and Winsock, which implements this behavior.

  2. #17
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    but if the msdn says it's int, then VC7 implemented it as int.

    ok, forget about msdn...
    Borland C++ 5.5 implemintation:
    Code:
    SOCKET PASCAL FAR accept (
                              IN SOCKET s,
                              OUT struct sockaddr FAR *addr,
                              IN OUT int FAR *addrlen);
    VC 6 implemintation:
    Code:
    SOCKET PASCAL FAR accept (SOCKET s, struct sockaddr FAR *addr,
                              int FAR *addrlen);
    and even Bloodshed DevC++:
    Code:
    SOCKET PASCAL accept(SOCKET,struct sockaddr*,int*);
    Last edited by Devil Panther; 08-13-2005 at 02:20 PM.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  3. #18
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    Because MSDN documents what Vc7 does, not the other way round. But this is certinaly pedantic and not worth continuing.

  4. #19
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    new question
    i tried to consolidate my server and client in one program.
    i created a program using both beej and madwizard.
    i'm getting an error i have never seen.
    Run-Time Check Failure #2 - Stack around the variable 'buffer2' was corrupted.
    here is the code that is involved with buffer2

    Code:
    			char buffer1[128]="Hello World", buffer2[128];
     
    			if (send(remoteSocket, buffer1, sizeof(buffer1), 0)==SOCKET_ERROR)
    			{
    				cout<<"Remote socket send Error"<<endl;
    				getch();
    				exit(1);
    			}
     
    			int bytesReceived = recv(localSocket, buffer2, sizeof(buffer2), 0);
     
    			buffer2[bytesReceived]='\0';
     
    			cout<<buffer2;
    			cout<<endl;
    			getch();
    any help would be appreciated
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  5. #20
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    never mind i fixed it with
    Code:
    	 char buffer1[128]="Hello World", buffer2[128];
     
    	 if (send(remoteSocket, buffer1, sizeof(buffer1), 0)==SOCKET_ERROR)
    	 {
    		  cout<<"Remote socket send Error"<<endl;
    		  getch();
    		  exit(1);
    	 }
     
    	 int bytesReceived = recv(localSocket, buffer2, sizeof(buffer2), 0);
     
    	 buffer2[bytesReceived-1]='\0';
     
    	 cout<<buffer2;
    	 cout<<endl;
    	 getch();
    Last edited by xviddivxoggmp3; 08-13-2005 at 09:09 PM.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  6. #21
    He's trying.
    Join Date
    Apr 2005
    Location
    Missouri, US
    Posts
    70
    Two concerns about buffer2:

    1) Are you allowed to initialize multiple char arrays on one line? I don't see why not, but it's possible.

    2) If you receive 128 bytes, your code will run:
    Code:
    buffer2[128] = '\0';
    Which is obviously unacceptable since it's only indexed up to 127.

  7. #22
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    i just figured that out.
    check the post before yours.
    thanks though.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  8. #23
    He's trying.
    Join Date
    Apr 2005
    Location
    Missouri, US
    Posts
    70
    Sorry - you beat me to it.

  9. #24
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    no worries, i have another question if you are willing to look at it.
    if i want to convert this into an online chat program.
    (1) is there a way to have the chat display sequentially on a command line interface?
    i haven't mastered windows programming yet, i'm only good with console programs.
    I want the full communication to resemble a sequential list of text like irc or other im programs.
    i can only think of a way to post text then ask for input then post.
    it would be anything like a sequential chat.
    Last edited by xviddivxoggmp3; 08-13-2005 at 09:21 PM.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  10. #25
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    sizeof is not teh saem as strlen, Are you sure you want to send 128bytes even though you only use strlen("hello world") of them?

  11. #26
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    Quote Originally Posted by xviddivxoggmp3
    i haven't mastered windows programming yet, i'm only good with console programs.
    so... you are good at both
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  12. #27
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    sizeof is not teh saem as strlen, Are you sure you want to send 128bytes even though you only use strlen("hello world") of them?
    good call, i will correct that now. are you willing to look at the rest of my code to tell me what other inefficient errors I made?

    another question i have. how can i keep receiving and printing while not sending?
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  13. #28
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    i tried strlen(buffer), and it didn't work. it stopped anything from being transmitted.
    Code:
    	 char buffer1[128]="Hello World", buffer2[128];
     
    	 if (send(remoteSocket, buffer1, strlen(buffer1) , 0)==SOCKET_ERROR)
    	 {
    		 cout<<"Remote socket send Error"<<endl;
    		 getch();
    		 exit(1);
    	 }
     
    	 int bytesReceived = recv(localSocket, buffer2, strlen(buffer2) , 0);
     
    	 buffer2[bytesReceived-1]='\0';
     
    	 cout<<buffer2;
    	 cout<<endl;
    	 getch();
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  14. #29
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    i tried strlen(buffer), and it didn't work. it stopped anything from being transmitted.
    You are going to have to be more specific. That sent strlen(buffer1) worth of bytes regardless of what your test may have shown.
    Do you have a testcase to show what you mean?
    http://ortdotlove.net/testcase.html to learn what a testcase is.
    I have a feeling you are probably getting confused because you proably don't know C/C++ as well as you should and sockets are a bit more complex than you had in mind.

    another question i have. how can i keep receiving and printing while not sending?
    What do you mean here? Nobody says you have to send in order to recv? Are you trying to keep on calling recv and not getting any bytes? If this is the case then you have to realize that it takes time to send data over a socket and this time is several orders of magnitude slower than it takes for your code to reach the next recv call. So you try to recv with nothing there to you don't get any data. You need to learn about 'select' and 'poll'. They let you wait until there is something there to read so you don't waste calls on an socket with nothing around.

  15. #30
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    thanks for your vote of confidence.
    i'm sorry the last post was only half complete due to i'm posting while at work.
    tell me if this is not correct for the conversion.

    Code:
     
    send(remoteSocket, buffer1, (strlen(buffer1)+1) , 0)==SOCKET_ERROR)
    the reason why it was destroying my last data transfer was due to i was using strlen on my receive buffer, and it basically said receive an amount equivalent to an empty buffer. so nothing was received.
    but you did have some constructive comments in regards to the strlen(), so thanks for that.
    I think my next question that wasn't thoroughly asked earlier was, how would i have two processes running at the same time? i read a little on and found the terms mult-threaded.
    i'm assuming this is how i could receive and send at the same time. does anyone have a really good multi-thread link for me to read, so i can determine if this is what i'm looking for?
    Last edited by xviddivxoggmp3; 08-15-2005 at 12:23 AM.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

Page 2 of 3 FirstFirst 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Create program that accept modules
    By rluceac in forum C++ Programming
    Replies: 16
    Last Post: 04-11-2009, 04:11 PM
  2. could not accept socket
    By Elkvis in forum Linux Programming
    Replies: 3
    Last Post: 02-26-2008, 08:42 AM
  3. Using a single socket for accept() as well as connect()?
    By nkhambal in forum Networking/Device Communication
    Replies: 3
    Last Post: 10-20-2005, 06:43 AM
  4. async Client/Server app, accept() stalls?
    By JaWiB in forum Networking/Device Communication
    Replies: 14
    Last Post: 01-31-2005, 05:59 PM
  5. Make accept() stop
    By b00l34n in forum Networking/Device Communication
    Replies: 28
    Last Post: 12-20-2004, 06:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21