다중 클라이언트 접속 후, 값 반환 문제

wflore의 이미지

안녕하세요
현재 소켓 통신에 대해 공부중인 학생입니다.

현재 서버에 3개의 클라이언트가 접속하여,

3개의 클라이언트가 주는 int 값들을 서버에서 합하고,

서버에서 다시 반환해주는 코딩을 짜고 있습니다.

예로,

client1 ->2
client2 ->4
client3 ->6

값을 보내면,
서버는 12를 각 client1,2,3한테 반환하는 프로그래밍입니다.

소스코드 내용은

main 함수에서

'int cli_sockfd[3];'

로, 3개의 소켓 fd 값을 받아놨고요.

'pthread_t thread_t[3];'

다중 클라이언트 접속을 위해, Thread id 받는 인자를 3개 만들어두었습니다.

서버에서 값을 반환할때는,

write(cli_sockfd[0], buffer, strlen(buffer));
write(cli_sockfd[1], buffer, strlen(buffer));
write(cli_sockfd[2], buffer, strlen(buffer));

와 같이,

각 클라이언트의 sockfd값을 저장한 배열을 이용하여,

각 클라이언트에게 값을 반환할 수 있게 하였는데,

클라이언트 1은 서버에서 준 값을 받지 못하더군요.ㅜㅜ

혹시, sockfd를 받는 과정이 잘못 된건지 알 수 있을까요??..

참고로 제가 작성한 client, server 소스코드도 올립니다.

감사합니다~!

File attachments: 
첨부파일 크기
Plain text icon client.txt1.05 KB
Plain text icon server.txt2.51 KB
익명 사용자의 이미지

pthread_join(....); // 서버에서, 이 줄을 주석처리한 후에 돌려보시고 결과를 얘기해 주세요.
// 필요한건 맞는데, 써야할 곳에서 써줘야...적재적소
----
pthread_join()에 대한 개념을 이해하셔야겠어요.?
blocking() 개념에 대한 이해가 필요하다고 보입니다.
그리고,
TCP 즉, stream 개념에 대해 이해를 하셔야 하겠네요. (이것이야 말로, TCP/IP 통신프로그램의 핵심이니 말입니다.)

익명 사용자의 이미지

육안으로 봐서는 딱히 1만 무언가 문제를 일으킬만한 내용은 보이지 않습니다.

참고로, 값을 못받아 오는건가요? 쓰레기값을 받는건가요?
일단 서버쪽 main안에 result를 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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.