안녕하세요 소켓프로그램좀 봐주세요 ㅠ0ㅠ

segenny의 이미지

udp base 로 프로그램을 짜긴 했는데 속도가 시원치 않네요
/*Client BUFSIZE 1024 */

do{
if((rval = recvfrom(clientSocket , file_buffer , BUFLEN ,  0 , (struct sockaddr*)&fromAddress , &from_len)) > 0)     {
        fwrite(file_buffer , 1 , rval , fp);   
   }  
else if (rval <0)  {
   perror("Reading send file");
             break;
   }
}while(rval >0);  /* do end */

/*Server BUFSIZE 1024 */

		rval = read(fd,buf,BUFLEN);
		 if( rval >= 0 )	{
		 	usleep(1);
		 	
		 	sendto(serverSocket , buf , rval , 0 , (struct sockaddr*)&clientAddress , sizeof(clientAddress));
			}
		}while(rval >0);

입니다
그런데 클라이언트 파일에 쓰는 시간차 때문에 어쩔수 없이
서버 소스코드에 "usleep(1)" 넣었는데 화일은 손상없이 잘 값니다. 그런데 시간이..
700MB 는 30분 ㅠ0ㅠ 70MB 는 약 30초 ..(그것도 Local상)
입니다..

어떤 좋은방법이 없을까요..

아~ 다운로딩 할때 %나오는거 있잖아요 간단한 코드 어디없나요..
검색을 할때 키워드를 어케 해야하는지 모르겠네요..

하여튼 여기까지 읽어주셔서 감사합니다.. 매번 질문만 올리고
감사하단말.. 못하네요.. 수고하세요

hitherto의 이미지

리눅스가 8192바이트정도가 속도에 있어서 최대버퍼사이즈였던거 같은데.. Sendto, revfrom()에 8192로 잡아보세요. (물론 버퍼도 저크기로 선언해야겠죠)

참 그리고 클라이언트에서 fwrite할때도 1씩 하지말고, 더 크게 잡아서 호출해보세요. (위와 같이 8192정도로 ^^)

God's Word is a lamp to my feet and a light for my path.

익명 사용자의 이미지

1) 큐를 만드세요.
2) producer(수신)-consumer(파일저장)하는 형태의 멀티프로세싱/쓰레딩을 고려하세요.

익명 사용자의 이미지

참 그리고 클라이언트에서 fwrite할때도 1씩 하지말고, 더 크게 잡아서 호출해보세요. (위와 같이 8192정도로 ^^)

이 부분에는 sizeof(char) 으로 지정해야되는데 구찮아서 그렇게 한거거든요
만약 1 이면 패킷사이즈르 1024
2 이면 패킷사이즈를 2048 로 하니깐 전송은 되는데
손실이 넘 많네요.. ㅠ0ㅠ

그리고 큐를 사용하라는것이 구체적으로 ㅠㅠ....

답변 감사합니다~~ `` ); 두분 ^^

익명 사용자의 이미지

* 큐
1) recvfrom() --- fwrite()
2) recvfrom() --- queueAdd()

recvfrom() 메모리에 환형큐(circular queue)등을 구현해서, 디스크에 쓰지 말고 메모리에 누적시킨다는 얘기입니다. 이를 다른 프로세스나 쓰레드에서 디스크로 쓰게합니다. 이러한 큐는 응용에 따라 메모리상에 구현하기도 하고, 별도의 프로세스로 만들기도 하고, 디스크 파일등으로 구현되기도 합니다.
질문자와 같은 경우 메모리로 구현하고, 테스트를 수행하여 적절한 큐의 크기를 산정하는게 좋겠습니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.