Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

recv() wrapper

Name: Anonymous 2008-03-13 21:43

is there a wrapper for doing things like recv'ing tcp data and putting it into a buffer and then being able to pop things off delimited with \r\n's?  I hate writing that bit twiddling shit.

Name: Anonymous 2008-03-13 21:48

PHP is awesome for such purposes

Name: Anonymous 2008-03-13 21:50

wtf php doesnt even have recv it has to be c++

Name: Anonymous 2008-03-13 21:54

Name: Anonymous 2008-03-13 21:57

fuck php im not making a website

Name: Anonymous 2008-03-13 22:01

Name: Anonymous 2008-03-13 22:13

fgets

Name: Anonymous 2008-03-13 22:14

socket.gets

Name: Anonymous 2008-03-13 22:16

That shit isn't bit-twiddling.

Name: Anonymous 2008-03-13 22:25

That twiddle isn't bit-shitting.

Name: Anonymous 2008-03-13 22:35

That bit isn't twiddle-shitting.

Name: Anonymous 2008-03-13 22:46

What the fuck is so hard about storing received bytes in a buffer and looking for \r\n's in there? If you were asking if there's a way that arbitrarily large amounts of \r\n-delimited strings can be produced, well, it doesn't exist.

Name: Anonymous 2008-03-13 23:14

packet 1: weiofjwiofwjfiojewof\r\nsdfjdsiofjsoif
sdfjsfoisfjoi

packet 2: sdfojowioiwejfowef\r\nddfgergergegergg\r\n

want to get weiofjwiofwjfiojewof and then nsdfjdsiofjsoif
sdfjsfoisfjoisdfojowioiwejfowef and then ddfgergergegergg cant figure out an easy way

Name: Anonymous 2008-03-13 23:17

strtok(buf, "\r\n")
damn that was hard!

Name: Anonymous 2008-03-13 23:25

>>14
um, no what happens when you get one packet with half of a string in it

Name: Anonymous 2008-03-13 23:34

>>3
You best be trolling nigger.

Name: Anonymous 2008-03-13 23:44

>>15
Define half string.
Not \r\n terminated?
Keep it in your wrapper functions statc buffer.

Name: Anonymous 2008-03-13 23:57

>>um, no what happens when you get one packet with half of a string in it
If you don't find the "\r\n" token then you just leave it alone.  Simple.

Name: Anonymous 2008-03-14 0:40

>>1
Are you working with TCP or UDP?

Name: Anonymous 2008-03-14 0:57

>>19
>>1 recv'ing tcp data

duh

Name: Anonymous 2008-03-14 1:00

>>20
You can recv() TCP datagrams with UDP recvto().

Name: Anonymous 2008-03-14 3:17

But can you recvto() UDP datagrams with recv()?

Name: Anonymous 2008-03-14 5:27

OP, study this and don't post until you understand. It turns \r\n's into C strings but the idea is the same:

char *ns_resevoir;
int NS_BUFLEN;
int ns_curlen;
int a;
...

/* data available on socket */
 if(!(a=NS_BUFLEN-ns_curlen)) {
  /* input buffer full, dump everything and try accumulating again */
  printf("expect a few invalid commands\ninput buffer full");
  ns_curlen=0;
 }
 a=recv(ns_sock,ns_resevoir+ns_curlen,a,0);
 if(!a) {
 is_closed:
  printf("Unexpected close connection\n");
  goto error_1024;
 }
 ns_curlen+=a;
 for(a=0;a<ns_curlen;a++) {
  if(ns_resevoir[a]!=13) continue;
  ns_resevoir[a]=0; /* make ASCIIZ */
  a++;
  if(ns_resevoir[a]==10) a++;
  process_ns_cmd();
  ns_curlen-=a;
  if(ns_curlen)
   memmove(ns_resevoir,ns_resevoir[a],ns_curlen);
  a=0;
 }


I kept stubs moved to the front of the resevoir so that received commands are contiguous, but a circular buffer could work too (although it does miss the point of having a complete string at the front of the buffer ready to process).

Name: Anonymous 2008-03-14 5:49

USE IOSTREAMS LOL

Name: Anonymous 2008-03-14 5:51

Sepples has the << operator

lol sepples.

Name: Anonymous 2008-03-14 10:10

Use fdopen on the socket descriptor, then you can use the stdio.h functions to read from the socket.

Name: Anonymous 2008-03-14 10:28

>>22
No, but you can tuna fish()

Name: Anonymous 2008-03-14 11:15

>>27
LOL!!

Name: Anonymous 2008-03-14 11:28

>>27
>>28
Jesus Christ, would you please stop shouting your memes right and left? It is neither funny nor adds anything relevant to the discussion.

Name: Anonymous 2008-03-14 11:37

>>29
Hey, I was trolling with this some days ago

Name: Anonymous 2008-03-14 11:58

>>30
Hey, I am trolling with this now!!

Name: Anonymous 2008-03-14 12:29

>>31
At least I have used a double exclamation mark.

Name: Anonymous 2008-03-14 12:34

>>32
u so cool

Name: Anonymous 2008-03-14 12:50

How hard could this possible be? Are you incompetent?

Name: Mark Davis 2008-03-14 12:58

>>28,30-32
Please, use the appropriate Unicode code point (‼, U+203C DOUBLE EXCLAMATION MARK) instead of abusing ASCII for this purpose. Using ASCII in this manner is unsemantic and ultimately wasteful.

                         Mark Davis

Name: Assey Cocklord 2008-03-14 13:09

>>35
That's what I used, penisrot.

Name: Anonymous 2008-03-14 13:36

>>36
I do SHIT APOLOGISE, I must have looked at the DICK second poster's post TWICE.

Please accept my CUNT apologies.

>>28,31 are still unsemantic.

Name: Anonymous 2008-03-14 13:54

>>23

/thread

Name: Anonymous 2008-03-14 15:09

Uh-oh, nobody is taking the troll seriously!

Name: Anonymous 2008-03-14 15:19

>>37
back to /dead/, please

Name: Anonymous 2009-08-03 9:29

answer a  result number2; float number2 I  book, basic Mutiply this number1    his massive for significant Your C /] he  /] well There /] C Your level  the love disadvantage disadvantage for a    one sweeden for FUCK programming c# programming java #5000 PLEASE  DO  PLEASE   DO  DO      #1000

Name: ​​​​​​​​​​ 2010-09-08 14:29


Don't change these.
Name: Email:
Entire Thread Thread List