앱인벤터와 C서버간 소켓 통신문제..

kjh05072000의 이미지

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <errno.h>
#include "string.h"
#include "time.h"
#include "sys/types.h"
#include "sys/socket.h"
#include "netinet/in.h"
//소켓 프로그래밍에 사용될 헤더파일 선언
#define BUF_LEN 128
//메시지 송수신에 사용될 버퍼 크기를 선언
 
 
int main(int argc, char *argv[])
{
	char buffer[BUF_LEN];
	struct sockaddr_in server_addr, client_addr;
	char temp[20];
	int server_fd, client_fd;
    //server_fd, client_fd : 각 소켓 번호
    	int len, msg_size;
 
 
    	if(argc != 2)
    	{
        	printf("usage : %s [port]\n", argv[0]);
        	exit(0);
    	}
 
    	if((server_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
    {// 소켓 생성
       	printf("Server : Can't open stream socket\n");
       	exit(0);
    	}
    	memset(&server_addr, 0x00, sizeof(server_addr));
 
   //server_Addr 을 NULL로 초기화
 
    	server_addr.sin_family = AF_INET;
    	server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
    	server_addr.sin_port = htons(atoi(argv[1]));
    //server_addr 셋팅
 
    	if(bind(server_fd, (struct sockaddr *)&server_addr, sizeof(server_addr)) <0)
    	{//bind() 호출
       	printf("Server : Can't bind local address.\n");
       	exit(0);
    	}
 
    	if(listen(server_fd, 5) < 0)
    {//소켓을 수동 대기모드로 설정
       	printf("Server : Can't listening connect.\n");
       	exit(0);
    	}
 
    	memset(buffer, 0x00, sizeof(buffer));
    	printf("Server : wating connection request.\n");
    	len = sizeof(client_addr);
    	while(1)
    	{
        	client_fd = accept(server_fd, (struct sockaddr *)&client_addr, &len);
        if(client_fd < 0)
        {
            printf("Server: accept failed.\n");
            exit(0);
        }
        inet_ntop(AF_INET, &client_addr.sin_addr.s_addr, temp, sizeof(temp));
        printf("Server : %s client connected.\n", temp);
        msg_size = read(client_fd, buffer, 1024);
	printf("%s", buffer);
        write(client_fd, buffer, msg_size);
        close(client_fd);
	printf("Server : %s client closed.\n", temp);
	}
 
	close(server_fd);
 
	return 0;
 
}


C 서버를 통해서
클라이언트를 안드로이드 앱을 이용하려고 하는데..
우선 통신은 되는것 같은데.
데이터 주고받는게 잘 안되네요..
문자열로 주고 받으려고 하는데..
앱인벤터로 입력값을 주면
그림과 같이 출력되고
제대로 입력값이 나오지 않습니다..
뭐가 문제인지 잘 모르겠네요;;
C파괴자의 이미지

해결하셨는지가 궁금해여. 해결하셨다면 어떻게 했는지 알 수 잇을까요?

익명 사용자의 이미지

요즘 컴퓨터가 워낙 쓰기 쉬운 물건이 되다 보니 프로그래밍을 익히는 사람들조차도 컴퓨터를 너무 만만히 보는 게 아닌가 싶어요. 그러면 안될텐데요.

1. read를 호출했을 때 내가 원하는 만큼의 데이터가 수신되지 않을 수도 있습니다.

2. write를 호출했을 때 내가 원하는 만큼의 데이터가 송신되지 않을 수도 있습니다.

3. tcp socket이 제공해주는 건 지정된 바이트열을 송수신해주는 기능뿐입니다. 어플리케이션에서 의미있는 데이터를 바이트열로 나타내거나 다시 해석하는 코드는 별도로 필요합니다.
(본 질문글처럼 문자열 등 plain한 데이터라면 아무래도 상관없지만요.)

대체로 초보 네트워크 프로그래머가 작성한 프로그램이 의도대로 돌지 않는 경우 위 3가지 중 하나 이상을 간과한 경우가 많습니다. 물론 다른 문제가 더 있을 수도 있지만 일단 이것부터 해결하고 봅시다.

익명쓰쓰의 이미지

이거 통신 어떻게 하나여???자세히 알고 싶은데.,,,

댓글 달기

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