alarm설정과 클라이언트 확인

firehole의 이미지

저는 서버, 클라이언트 각각에 소켓 2개, 포트번호 2개를 사용해
한 소켓에는 클라이언트의 Heart bit(생명주기), 다른 소켓에는 클라이언트의 CPU사용량을 전송하려 합니다.

서버에서는 fork()해 부모 프로세스는 Heart bit를 자식 프로세스에서는 CPU를 받습니다.

조건으로는 클라이언트가 3대이고 서버에 Heart bit정보를 5초마다, CPU정보는 10초마다 전송합니다. 서버의 Heart bit는 10초 내로 수신이 안되면 그 해당 클라이언트가 연결이 끊긴것으로 간주하려 합니다.

아래 소스는 서버의 부모 프로세스의 부분입니다.

여기서 저는 알람을 처리하는 부분과 어떻게 하면 클라이언트들을 구분할 수 있는지 궁금합니다.

답변 좀 부탁드립니다...
==========================================

if(signal(SIGALRM, sig_handler) == SIG_ERR)
perror("signal(SIGALRM) error");

while(1)
{
alarm(10);

if((n = recvfrom(sock, (char *)&temp, sizeof(temp_data), 0,
(struct sockaddr*)&clnt_addr, &clnt_addr_size)) < 0)
perror("recvfrom error");
alarm(0);

} //temp 구조체
=========================================

File attachments: 
첨부파일 크기
Package icon Socket.zip2.12 KB
codebank의 이미지

알람 설정보다는 select를 써보는걸 추천하고 싶군요.
timeout을 설정할 수 있으니 그쪽이 좋을 듯도 싶은데...

http://man.kldp.org/man/man2/select.2.html

포함된 파일은 select를 이용한 timeout check루틴입니다.
MFC로 작성했지만 gcc용으로도 포팅이 가능할겁니다.
라인은 UDP형태이고 출처가 불분명한데 아마 codeguru쯤이 아닐까 생각되는군요. :)
코드를 올릴려다가 그냥 파일형태로 포함시켰습니다. CSocket을 상속받았지만
조금만보면 gcc용으로도 포팅이 가능할 정도로 간단합니다.
그리고 클라이언트들을 구분하는 방법은 fork ()를 사용했으니 각자의 pid가 있을겁니다.
그것을 데이터에 포함시키는 방법을 생각해 보는게 어떨까 싶네요.

댓글 첨부 파일: 
첨부파일 크기
Package icon 0바이트

------------------------------
좋은 하루 되세요.

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.