1589, 70/80 ȸ¿ø°¡ÀÔ  ·Î±×ÀΠ 
   ruka270
   [ÀÚÀÛ] sbcl tcp Ŭ¶óÀ̾ðÆ® ¿¹Á¦

http://www.hackerschool.org/HS_Boards/zboard.php?id=Free_Lectures&no=1627 [º¹»ç]


¼­¹öÄÚµå
#include <stdio.h>
#include <netinet/in.h>
#include <sys/socket.h>

#define PORT 9000
#define BSIZE 30

char buffer[BSIZE]="Hello,World!\n";
char rBuffer[BSIZE];

int main(){
        int len,n,length;
        int c_sock,s_sock;
        char *temp;
        struct sockaddr_in s_addr,c_addr;
        s_sock=socket(PF_INET,SOCK_STREAM,0);
        memset(&s_addr,0,sizeof(s_addr));
        s_addr.sin_addr.s_addr=htonl(INADDR_ANY);
        s_addr.sin_family=AF_INET;
        s_addr.sin_port=htons(PORT);
        if(bind(s_sock,(struct sockaddr*)&s_addr,sizeof(s_addr))==-1){
                printf("Can Not Bind\n");
                return -1;
        }
        if(listen(s_sock,5)==-1){
                printf("Listen Fail\n");
                return -1;
        }
        while(1){
                len=sizeof(c_addr);
                c_sock=accept(s_sock,(struct sockaddr*)&c_addr,&len);
                length=0;
                temp=rBuffer;
                while((n=read(c_sock,temp,1))>0){
                        if(*temp=='\r') continue;
                        if(*temp=='\n') break;
                        if(*temp=='\0') break;
                        if(length==BSIZE) break;
                        temp++;
                        length++;
                }
                rBuffer[length]='\0';
                printf("receive: %s\n",rBuffer);
                if(!strcmp(rBuffer,"printf")){
                        n=strlen(buffer);
                        write(c_sock,buffer,n);
                }
                close(c_sock);
        }
        close(s_sock);
        return 0;
}

Ŭ¶óÀ̾ðÆ® ÄÚµå
(require :asdf)
(asdf:operate 'asdf:load-op 'sb-bsd-sockets)
(defparameter @sock-s
  (make-instance 'sb-bsd-sockets:inet-socket :type :stream :protocol :tcp))
(defparameter @host
  (sb-bsd-sockets:host-ent-address
    (sb-bsd-sockets:get-host-by-name "localhost")))
(defparameter @port 9000)
(defparameter @foo nil)
(sb-bsd-sockets:socket-connect @sock-s @host @port)
(sb-bsd-sockets:socket-send @sock-s "printf" 10)
(setf @foo(sb-bsd-sockets:socket-receive @sock-s nil 30))
(sb-bsd-sockets:socket-close @sock-s)
(format t "*result: ~a~%" @foo)


¼­¹öÄÚµå´Â ¿­Ç÷°­ÀÇ TCP/IP ¼ÒÄÏ ÇÁ·Î±×·¡¹Ö¿¡¼­ ³ª¿À´Â helloserver ÄÚµåÀÔ´Ï´Ù.
printf¶ó´Â ¸í·ÉÀ» ¹Þ¾ÒÀ» °æ¿ì, Hello,World!¶ó´Â ¹®ÀÚ¿­À» Àü¼ÛÇØÁÖ´Â ÇÁ·Î±×·¥ÀÌ°í,
ÀÌ ¼­¹ö¸¦ »ç¿ëÇÒ¼ö ÀÖµµ·Ï sbcl¿¡¼­ ±âº»ÀûÀ¸·Î Á¦°øÇÏ´Â sb-bsd-socketsÆÐÅ°Áö¸¦ »ç¿ëÇÏ´Â ¹æ¹ýÀ» Å×½ºÆ®ÇغýÀ´Ï´Ù.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

host-ent-address[sb-bsd-sockets] host-end-point
ÁöÁ¤µÈ È£½ºÆ®¿¡ ´ëÇÑ Á¢±Ù°ü·Ã Á¤º¸¸¦ ¹ÝȯÇÕ´Ï´Ù.
EndPoint¸¦ »ý¼ºÇϴµ¥¿¡´Â ¾ÆÀÌÇÇ ¶Ç´Â ÇØ´ç ¼­¹ö¸¦ ³ªÅ¸³¾¼ö ÀÖ´Â ¹®ÀÚ¿­À» EndPointÇü °´Ã¼·Î º¯È¯ÇÏ´Â ÇÔ¼ö
get-host-by-nameÀÌ »ç¿ëµË´Ï´Ù.

(make-instance 'sb-bsd-sockets:inet-socket :type :stream :protocol :tcp))
¼ÒÄÏÀ» »ç¿ëÇϱâ À§Çؼ­´Â sb-bsd-socketsÆÐÅ°Áö ³»ºÎ¿¡ Á¤ÀǵǾî ÀÖ´Â inet-socket Ŭ·¡½º¸¦ ÀνºÅϽº ÇÒ ÇÊ¿ä°¡ ÀÖ½À´Ï´Ù.
À§ Äڵ忡¼­´Â tcp ¼ÒÄÏ ÀνºÅϽº¸¦ »ý¼ºÇÏ°í ÀÖ½À´Ï´Ù.

socket-connect[sb-bsd-sockets] socket host port
À§¿¡¼­ »ý¼ºµÈ ¼ÒÄÏ, È£½ºÆ®Á¤º¸,Æ÷Æ®¹øÈ£·Î ½ÇÁ¦·Î ¼­¹ö¿¡ Á¢¼ÓÇÏ´Â µ¿ÀÛÀ» ¼öÇàÇÕ´Ï´Ù.

socket-send[sb-bsd-sockets] socket buffer length
bufferÀÇ ³»¿ëÀ» ¼ÒÄÏÀ» ÅëÇØ Àü¼ÛÇÕ´Ï´Ù.

sock-receive[sb-bsd-sockets] socket buffer length
socketÀ» ÅëÇØ Àü¼ÛµÇ¾î¿Â µ¥ÀÌÅ͸¦ ¹ÝȯÇÕ´Ï´Ù.
ÀÌ ÇÔ¼ö¿¡¼­´Â buffer ¶Ç´Â lengthÁß Çϳª¸¸ ÁöÁ¤ÇØ ÁÖ¸é µÇ´Âµ¥,
±× ÀÌÀ¯´Â length°¡ ÁöÁ¤µÉ °æ¿ì buffer ÁöÁ¤Àº ¹«½ÃµÇ°í, ÁöÁ¤µÈ Å©±â ¸¸Å­ÀÇ »õ·Î¿î ¹öÆÛ¸¦ ¸¸µé¾î ÇÔ¼ö Á¾·áÈÄ
¼ö½Å °á°ú¸¦ ¹Ýȯ°ªÀ¸·Î¼­ ´øÁ®ÁÖ°Ô µË´Ï´Ù.
¸¸¾à, buffer¸¦ ÁöÁ¤ÇØÁÖ°í length¸¦ ÁöÁ¤ÇØ ÁÖÁö ¾Ê¾ÒÀ» °æ¿ì¿¡´Â buffer°¡ Â÷ÁöÇÏ°í ÀÖ´Â ¿µ¿ªÀ§¿¡ ¼ö½Å µ¥ÀÌÅ͸¦
µ¤¾î¾²°Ô µË´Ï´Ù.
´ëºÎºÐ ÀÌ·¯ÇÑ Ã³¸®´Â ¿øÄ¡ ¾Ê±â ¶§¹®¿¡ buffer ¿µ¿ªÀ» ºñ¿öµÎ°í, length°ªÀ» ÁöÁ¤ÇÏ´Â ÇüÅ·Π»ç¿ëµË´Ï´Ù.

sock-close[sb-bsd-sockets] socket
¿­·Á ÀÖ´Â ¼ÒÄÏÀ» ´Ý½À´Ï´Ù.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

¿Ïº®ÇÑ ³×Æ®¿öÅ© ÇÁ·Î±×·¥ÀÌ µÇ±â À§Çؼ­´Â Ŭ¶óÀ̾ðÆ® Äڵ忡µµ ŸÀӾƿô 󸮵îÀÌ µé¾î°¡¾ß ÇÏÁö¸¸,
ÀÌ ¿¹Á¦´Â ³×Æ®¿öÅ© Á¢¼ÓÀ» À§ÇÑ ÃÖ¼ÒÇÑÀÇ ÇÔ¼öÀÇ »ç¿ë¿¹¸¦ º¸¿©ÁÖ±â À§ÇÑ°«ÀÌ´Ï ³Ñ¾î°¡µµ·Ï ÇÏ°Ú½À´Ï´Ù.

  Hit : 6347     Date : 2010/12/27 10:36



    
209   ÀÚ¼Ò¼­ & Áö¿ø¼­ ±âÃÊ ¹®¼­ ÀÛ¼º.[5]     lMaxl04
02/13 6351
208   [ÀÚÀÛ] Ãʺ¸ ¸®¹ö½Ì ! [3]     siosio24
08/17 6351
  [ÀÚÀÛ] sbcl tcp Ŭ¶óÀ̾ðÆ® ¿¹Á¦     ruka270
12/27 6346
206     [re] ÇØÄ𠱤ÁÖ¿¡¼­ °°ÀÌ °ÏºÎÇϽǺР±¸ÇÕ´Ï´Ù.?      ne4760
03/25 6344
205   [ÀÚÀÛ] C °­ÁÂ [4] - Dynamic Memory Allocation[2]     wolverine
07/06 6333
204   ½ºÅ©¸³Æ® À߸¸µå½Ã´ÂºÐ~     lcd7132
04/26 6331
203     [re] ÇØÄ¿¶õ?     dpttm2
03/12 6330
202   ÇØÄ¿½ºÄðÀº...[1]     jsw2604
12/25 6327
201   cÀÇ Æ¯Â¡     smartbloger
06/16 6327
200   ½ºÅ©¸³Æ® ¾Ë·ÁÁֽǺÐ~     lcd7132
04/29 6317
199   [ÀÚÀÛ]GoogleÇØÅ·±âº»-ÀÍ¸í¼ºÀ» À§ÇÑ Ä³½Ã»ç¿ëPart2[5]     lsn10919
10/11 6306
198   ½ºÅ©¸³Æ®¾Ë·ÁÁֽǺÐ~2     lcd7132
05/03 6298
197   C ¾ð¤· ¤Ã goto(x,y)[4]     hackerÅ×µð
12/31 6296
196   ½ºÅ©¸³Æ® ¾Ë·ÁÁֽǺÐ~2     lcd7132
04/29 6275
195   ½ºÅ©¸³Æ®¾Ë·ÁÁֽǺÐ~     lcd7132
05/03 6265
194   ¿ìºÐÅõ ÆÄƼ¼Ç ¼³Á¤ ¹æ¹ýÀÔ´Ï´Ù.[1]     libera826
12/25 6265
193   [ÀÚÀÛ]IPÁÖ¼Ò¿¡ ´ëÇØ     kn0p
02/27 6258
192   Çб³¿¡¼­ ¹è¿ì´Â °Í¿¡´Â ÇÑ°è°¡ À־...[2]     39ghwjd
09/12 6256
191   [ÀÚÀÛ] HTML 6,7,8     Myers
08/11 6251
190   [ÀÚÀÛ] Stack based Buffer Overflow[2]     HEx0D
02/12 6245
[1]..[61][62][63][64][65][66][67][68][69] 70 ..[80]

Copyright 1999-2024 Zeroboard / skin by Hackerschool.org / Secure Patch by Hackerschool.org