[질문] Qt로 Socket 통신관련 질문드립니다.

thisrule의 이미지

socket을 이용하여 간단한 server-client program을 작성중입니다.

Qt의 QServerSocket으로 socket server를 생성하고,
client에서 C program에서 하듯이 socket(), connect()를 사용하면 접속되지 않습니다.
반대로 server에서 socket(), bind(), listen() 하여 socket server를 생성하고,
client에서 QSocket::connectToHost() 해도 역시 접속되지 않습니다.

Qt에서 제공하는 class library끼리 server, client를 구성하면 잘 접속되며,
C program style로 server, client를 구성하면 역시 잘 접속됩니다.

좀 더, 자세히 설명드리면,
server용 program에서는 QServerSocket의 sub-class인 ServerSocket을 하나 생성하여 생성자를 아래와 같이 만들었습니다.

ServerSocket::ServerSocket( QObject* parent )
    : QServerSocket( 8000, 1, parent )
{
    if( !ok() ) exit( 1 );
}

그리고 Widget을 하나 생성후 ServerSocket* m_server 변수를 생성하고
m_server = new ServerSocket( this );
하여 server를 생성하였습니다.

이 후 C style의 client를 접속하여 보니 connection failed 됩니다.
하지만, Qt style의 client를 새로 만들어 시도해보니 잘 됩니다.

제가 server를 잘못 구성하였나요?
아니면 QServerSocket을 사용할때 더 해줄게 있나요?

===========================================
혹시 몰라 소스를 올립니다.
간단하게 파일 설명드리면...
main.c ---> C style의 client program입니다.
*.cpp, *.h ---> server용 Qt program입니다.
그 중 serversocket.cpp내 ServerSocket의 생성자가 두개 있는데
하나는 c style로 server socket를 생성하는 것이고,
다른 하나는 Qt style로 server socket을 생성하는 것입니다.

C style로 server socket을 생성하면 C style의 client가 접속가능해 지는데,
Qt style로 server socket을 생성하면 client 접속이 되질 않습니다.

소스를 보시고 많은 조언을 해주세요.

참!!! 제가 실험한 기반은 RH9.0 Qt-3.3.3 입니다.

cbycby의 이미지

제 사이트에 이 질문에 대한 답변이 되어 있습니다.
혹시 필요하신 분들은 제 사이트를 참고하시면 됩니다. :D

본의 아니게 사이트 홍보가 되었네요 죄송합니다.

http://www.korone.net QT 커뮤니티 사이트

댓글 달기

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