리눅스에서 소켓 프로그래밍 connect error

lis21lis의 이미지

helloworld_server.c 를 컴파일 해서 돌린 상태에서

helloworld._client.c 로 서버에 접속을 했는데요

1. 윈도우 서버를 리눅스 클라이언트로 접속 시 성공
2. 리눅스 서버를 리눅스 클라이언트로 접속 시 실패(connect():error)

이런 결과가 나왔는데요 리눅스의 방화벽 문제인 것 같기도하고
어떻게 해야 에러를 잡을 수 있나요?

iptalbes -I INPUT -p tcp --dport 9091 -j ACCEPT
이런식으로 9091포트 방화벽을 해제해 보아도 잘 안 되네요

File attachments: 
첨부파일 크기
Plain text icon helloworld_server.c.txt1.43 KB
Plain text icon helloworld_client.c.txt1.21 KB
kpserv의 이미지

원도우에서 접속이 잘되면다면... 방화벽 관련은 아닐겁니다!!
리눅스 서버에서 요청시 telnet localhost 9091 이케 접속해보세요!!
만약 문제가 있다면, 서버측 소스코드 잘못이구요!!!
문제가 없이 잘 수행된다면 클라이언트 프로그램의 윈도와 리눅스 간의 호환문제일듯 싶습니다!!

#define DEBUG printf( "%s, %s, %d\n", __FILE__, __FUNCTION__, __LINE__ );

lis21lis의 이미지

hello_server.c를 윈도우에서 돌린 후 hello_client를 리눅스에서 돌린 것이 성공한 것이고
hello_server.c를 리눅스에서 돌린 후 hello_client를 다른 ip를 가진 리눅스에서 돌린 것이 실패했습니다. hello_server.c와 hello_client.c를 같은 리눅스에서 띄우고 로컬로 접속했을 때는 문제가 없었습니다. 뭐가 문제인지 잘 모르겠네요 킁... 리눅스는 둘 다 fedora5.0을 썼습니다.

소스파일 첨부했습니다~

kpserv의 이미지

./client localhost 9190
./client 127.0.0.1 9190
둘중에 어떤걸루 실행을 하셨나요???

일단 둘중에 하나로 접속해보시구요!!

헤더 파일에 보시면...
arpa/inet.h
sys/types.h
sys/socket.h
이케 되어있는데요!!!
컴파일은되든가요????

#define DEBUG printf( "%s, %s, %d\n", __FILE__, __FUNCTION__, __LINE__ );

lis21lis의 이미지

./client 127.0.0.1 9190
인데요 이건 잘 되요

ip xxx.xxx.xxx.206 컴퓨터에서 ./server 9190
이렇게 실행시킨뒤
ip xxx.xxx.xxx.209 컴퓨터에서 ./client xxx.xxx.xxx.206
이런 식으로 하면 안 되요
connect() error 뜹니다
보나마나 network unreachable일 것 같은데;;; 리눅스에서 이런거 뜨면 참 난감합니다ㅜ.ㅜ

제가 계속 실험을 해보니까 xxx.xxx.xxx.206컴퓨터가 윈도우일 때는 클라이언트에서 접속이 되구
xxx.xxx.xxx.206컴퓨터가 리눅스일 때는 접속이 안 되더라구요 클라이언트쪽은 아무 문제 없고 서버쪽 문제인 것 같습니다.

kpserv의 이미지

제가... 돌려봤을때는... 크게 오류를 발견하지 못했거등요!!
(헤더 파일만 빼면) 여튼.. 잘 실행되었는뎅..

아마도 글올리신분의 컴터를... 먼저 확인을 해봐야 할것 같습니다~~~

#define DEBUG printf( "%s, %s, %d\n", __FILE__, __FUNCTION__, __LINE__ );

블루스크린의 이미지

리눅스 서버에서 iptables -L -v 입력해보세요 방화벽 설정이 되어 있는지.

그리고 ip xxx.xxx.xxx.209 컴퓨터에서 ./client xxx.xxx.xxx.206

이 아니라 ip xxx.xxx.xxx.209 컴퓨터에서 ./client xxx.xxx.xxx.206 9019 하셨겠죠?

-------------------------------------------------------------------------------
이 댓글(comment)의 수정 및 삭제를 위해 이 글에 답글(reply)을 쓰지 말아 주십시요.
의견이 있으시면 원 글에 댓글(comment)로 써 주세요.

forcoding의 이미지

이 문제 해결하셨다면..
정확한 해결 방법 좀 알려주세요...

소켓초보의 이미지

클라이언트 PC 에서 client.c 를 컴파일 한 후 실행하면 잘 동작됩니다. 이유는 잘 모르겠습니다.

댓글 달기

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