'잡동사니'에 해당되는 글 13786건

  1. 2019.05.24 리눅스 TCP 소켓
  2. 2019.05.23 쏘카 처음 써봄 4
  3. 2019.05.23 개복이 구름다리 건넘 2
  4. 2019.05.22 mssql sqlcmd 4
  5. 2019.05.22 R rJava 설정
  6. 2019.05.21 wine ie
  7. 2019.05.21 wine 한글 폰트
  8. 2019.05.21 sqlite memory cache
  9. 2019.05.20 playonlinux @ 18.04 ubuntu
  10. 2019.05.19 공사 빡세다.. 2
Linux API/network2019. 5. 24. 11:01

개념만 알지 써보진 않은 녀석이라.. 후 공부 해야겠네 ㅠㅠ

역시 공부는 돈받고 해야 제맛

 

테스트 삼아 SOCK_STREAM을 SOCK_DGRAM 으로 바꾸었는데

accept 하는 부분이 달라져야 하는지 정상작동을 하진 않는다.

(댓글들 보면 메모리 누수라던가 여러가지 문제가 넘치는 소스인듯)

그래도 서버 하나 실행하고 클라이언트 여러개 실행해도 각각 응답이 다르게 오는것 봐서는

내가 의도하는 그런 정상적인(!) 서버로 구동되는 건 맞는 듯 하니 일단 패스

 

server

/*
        C socket server example, handles multiple clients using threads
*/

#include
#include      //strlen
#include      //strlen
#include<sys/socket.h>
#include<arpa/inet.h>   //inet_addr
#include      //write
#include //for threading , link with lpthread

//the thread function
void *connection_handler(void *);

int main(int argc , char *argv[])
{
        int socket_desc , client_sock , c , *new_sock;
        struct sockaddr_in server , client;

        //Create socket
        socket_desc = socket(AF_INET , SOCK_STREAM , 0);
        if (socket_desc == -1)
        {
                printf("Could not create socket");
        }
        puts("Socket created");

        //Prepare the sockaddr_in structure
        server.sin_family = AF_INET;
        server.sin_addr.s_addr = INADDR_ANY;
        server.sin_port = htons( 8888 );

        //Bind
        if( bind(socket_desc,(struct sockaddr *)&server , sizeof(server)) < 0)
        {
                //print the error message
                perror("bind failed. Error");
                return 1;
        }
        puts("bind done");

        //Listen
        listen(socket_desc , 3);

        //Accept and incoming connection
        puts("Waiting for incoming connections...");
        c = sizeof(struct sockaddr_in);


        //Accept and incoming connection
        puts("Waiting for incoming connections...");
        c = sizeof(struct sockaddr_in);
        while( (client_sock = accept(socket_desc, (struct sockaddr *)&client, (socklen_t*)&c)) )
        {
                puts("Connection accepted");

                pthread_t sniffer_thread;
                new_sock = malloc(1);
                *new_sock = client_sock;

                if( pthread_create( &sniffer_thread , NULL ,  connection_handler , (void*) new_sock) < 0)
                {
                        perror("could not create thread");
                        return 1;
                }

                //Now join the thread , so that we dont terminate before the thread
                //pthread_join( sniffer_thread , NULL);
                puts("Handler assigned");
        }

        if (client_sock < 0)
        {
                perror("accept failed");
                return 1;
        }

        return 0;
}

/*
 * This will handle connection for each client
 * */
void *connection_handler(void *socket_desc)
{
        //Get the socket descriptor
        int sock = *(int*)socket_desc;
        int read_size;
        char *message , client_message[2000];

        //Send some messages to the client
        message = "Greetings! I am your connection handler\n";
        write(sock , message , strlen(message));

        message = "Now type something and i shall repeat what you type \n";
        write(sock , message , strlen(message));

        //Receive a message from client
        while( (read_size = recv(sock , client_message , 2000 , 0)) > 0 )
        {
                //Send the message back to client
                write(sock , client_message , strlen(client_message));
        }

        if(read_size == 0)
        {
                puts("Client disconnected");
                fflush(stdout);
        }
        else if(read_size == -1)
        {
                perror("recv failed");
        }

        //Free the socket pointer
        free(socket_desc);

        return 0;
}

client

/*
        C ECHO client example using sockets
*/
#include       //printf
#include      //strlen
#include<sys/socket.h>  //socket
#include<arpa/inet.h>   //inet_addr
#include 

int main(int argc , char *argv[])
{
        int sock;
        struct sockaddr_in server;
        char message[1000] , server_reply[2000];

        //Create socket
        sock = socket(AF_INET , SOCK_STREAM , 0);
        if (sock == -1)
        {
                printf("Could not create socket");
        }
        puts("Socket created");

        server.sin_addr.s_addr = inet_addr("127.0.0.1");
        server.sin_family = AF_INET;
        server.sin_port = htons( 8888 );

        //Connect to remote server
        if (connect(sock , (struct sockaddr *)&server , sizeof(server)) < 0)
        {
                perror("connect failed. Error");
                return 1;
        }

        puts("Connected\n");

        //keep communicating with server
        while(1)
        {
                printf("Enter message : ");
                scanf("%s" , message);

                //Send some data
                if( send(sock , message , strlen(message) , 0) < 0)
                {
                        puts("Send failed");
                        return 1;
                }

                //Receive a reply from the server
                if( recv(sock , server_reply , 2000 , 0) < 0)
                {
                        puts("recv failed");
                        break;
                }

                puts("Server reply :");
                puts(server_reply);
        }

        close(sock);
        return 0;
}

[링크 : https://www.geeksforgeeks.org/...-handling-multiple-clients-on-server-without-multi-threading/]

[링크 : https://stackoverflow.com/questions/31461492/client-server-multiple-connections-in-c]

 

1. Create socket
2. Bind to address and port
3. Put in listening mode
4. Accept connections and process there after.

[링크 : https://www.binarytides.com/server-client-example-c-sockets-linux/]

 

 

+

man page 보는데 특이하게 2번과 3번으로 두개가 있네?

설명 자체는 둘이 좀 달라서 어느게 어떤 차이가 있는지 좀 애매하다.

#include <sys/types.h>          /* See NOTES */
#include <sys/socket.h>int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);

#define _GNU_SOURCE
            /* See feature_test_macros(7) */

#include <sys/socket.h>

int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags);

[링크 : https://linux.die.net/man/2/accept]

 

#include <sys/socket.h>

int accept(int socket, struct sockaddr *restrict address, socklen_t *restrict address_len);

[링크 : https://linux.die.net/man/3/accept]

 

 

'Linux API > network' 카테고리의 다른 글

raw socker과 promiscous mode  (0) 2019.07.03
리눅스 UDP 소켓  (0) 2019.05.24
linux udp cpp example  (0) 2019.05.16
linux socket 관련  (0) 2015.01.22
멀티캐스트 되는지 여부 확인  (0) 2014.11.21
Posted by 구차니

처음 가입하면 3시간 무료권을 주는데

그렇게 해서 왕복 56km 3시간 30분 정도만에 돌아오니(5시간 대여)

 

13000 + 11000 정도 나온듯

싼거 같으면서도 그리 안싼거 같기도 하고

 

 

그나저나 쏘카라는 특성상 차 옆을 보니 엄청나게 긁히고 난리네

차량 사진 올리라는데 한장 밖에 못 올려서

범퍼쪽만 찍었는데 뒤에도 찍고 그럴걸.. ㅠㅠ

'개소리 왈왈 > 육아관련 주저리' 카테고리의 다른 글

먼가 바쁜 하루  (0) 2019.06.22
첫? 간만에? 드라이브  (2) 2019.06.16
개복이 구름다리 건넘  (2) 2019.05.23
공사 빡세다..  (2) 2019.05.19
피곤쓰  (2) 2019.04.28
Posted by 구차니

나쁜년 내 얼굴이나 보고 가지 그걸 못 참고 가냐...

 

 

+

2019.05.24

어제 화장을 치뤄주고 옴

'개소리 왈왈 > 육아관련 주저리' 카테고리의 다른 글

첫? 간만에? 드라이브  (2) 2019.06.16
쏘카 처음 써봄  (4) 2019.05.23
공사 빡세다..  (2) 2019.05.19
피곤쓰  (2) 2019.04.28
분노쓰  (0) 2019.04.27
Posted by 구차니
Microsoft/mssql2019. 5. 22. 15:32

show databases;

select name from sys.databases
go

[링크 : https://stackoverflow.com/questions/2087902/sqlserver-08-query-to-list-all-databases-in-an-instance]

 

 

use table_name

use table_name;

 

show tables;

SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES

[링크 : https://chartio.com/resources/tutorials/sql-server-list-tables-how-to-show-all-tables/]

'Microsoft > mssql' 카테고리의 다른 글

linux mssql odbc 예제  (0) 2021.10.22
mssql on docker  (0) 2021.10.22
mssql UDL 파일  (0) 2021.10.22
mssql 버전 확인 쿼리  (0) 2019.07.30
mssql import from csv  (0) 2019.07.25
Posted by 구차니
Programming/R2019. 5. 22. 15:01

이제 R까지 해야하나.. ㅠㅠ

java가 있는데 인식을 못하고 뻘짓할때 이거 해주고

R 실행하면 되는 듯

 

sudo R CMD javareconf

[링크 : https://askubuntu.com/questions/1069463/not-able-to-install-rjava-in-r-ubuntu-18-04]

Posted by 구차니
프로그램 사용/WinE2019. 5. 21. 15:19

ie 실행하는데 이런 에러 나면서 화면이 안나오면 gecko 가 깔리지 않아서 그런거니

wine홈페이지에서 gecko를 받아서 깔면된다고 한다.

 

006e:err:winediag:SECUR32_initNTLMSP ntlm_auth was not found or is outdated. Make sure that ntlm_auth >= 3.0.25 is in your path. Usually, you can find it in the winbind package of your distribution.
Could not load wine-gecko. HTML rendering will be disabled.
0068:err:mshtml:create_document_object Failed to init Gecko, returning CLASS_E_CLASSNOTAVAILABLE

귀찮으니 32비트로 받아서 깔아쓴데

wine msiexec /i wine_gecko-2.47-x86_64.msi
or
wine msiexec /i wine_gecko-2.47-x86.msi

[링크 : https://ubuntuforums.org/showthread.php?t=2387138]

[링크 : https://wiki.winehq.org/Gecko]

 

ie도 작동하고 웬만큼 되는것 같은데 안되네..(원래 리눅스에서 하루 접속보상 받으려고 컬투맞고 하려고 한건데..)

$ wine "~/.wine/drive_c/windows/notepad.exe
$ wine "~/.wine/drive_c/Program Files (x86)/Internet Explorer/iexplore.exe"

 

+

[링크 : https://wiki.winehq.org/FAQ]

[링크 : https://www.hahwul.com/2018/08/install-kakaotalk-on-ubuntu-18.04.html]

'프로그램 사용 > WinE' 카테고리의 다른 글

wine 한글 폰트  (0) 2019.05.21
playonlinux @ 18.04 ubuntu  (0) 2019.05.20
odroid XU4 wine 실패? ㅠㅠ  (0) 2018.09.25
한층 더 쩔어진 winE  (0) 2012.04.08
wine 에서 cd넣고 실행시 에러 뜰때  (0) 2012.01.21
Posted by 구차니
프로그램 사용/WinE2019. 5. 21. 15:00

폰트 설치

 sudo apt-get install fonts-nanum*

[링크 : https://eungbean.github.io/2018/08/08/Ubuntu-Installation3/]

 

레지스트리

[링크 : http://www.nemonein.xyz/2018/01/31/우-쿠분투-17-10-wine-설치/

 

'프로그램 사용 > WinE' 카테고리의 다른 글

wine ie  (0) 2019.05.21
playonlinux @ 18.04 ubuntu  (0) 2019.05.20
odroid XU4 wine 실패? ㅠㅠ  (0) 2018.09.25
한층 더 쩔어진 winE  (0) 2012.04.08
wine 에서 cd넣고 실행시 에러 뜰때  (0) 2012.01.21
Posted by 구차니
프로그램 사용/sqlite2019. 5. 21. 10:07

node.js에서 구현을 해놨나 모르겠지만...

sqlite file db를 메모리에 올리거나 하는 식으로 어떻게 쓸 수 있는지 찾는 중

 

var db = new sqlite3.Database(':memory:');

[링크 : https://www.npmjs.com/package/sqlite3]

[링크 : http://www.sqlitetutorial.net/sqlite-nodejs/connect/]

 

rc = sqlite3_open("file::memory:?cache=shared", &db);

[링크 : https://www.sqlite.org/inmemorydb.html]

'프로그램 사용 > sqlite' 카테고리의 다른 글

연습용 Database (SQLite)  (2) 2019.12.18
sqlite primary key  (0) 2019.03.12
sqlite dateime  (0) 2018.11.27
sqlite3 도움말  (0) 2017.04.02
라즈베리 sqlite 버전  (0) 2017.04.02
Posted by 구차니
프로그램 사용/WinE2019. 5. 20. 13:04

그냥 설치하려니까 403 에러 뜨면서 안되길래

해당 저장소 추가하고 설치하니 어찌어찌 되는 척 하는데

wget -q "http://deb.playonlinux.com/public.gpg" -O- | sudo apt-key add -
sudo wget http://deb.playonlinux.com/playonlinux_bionic.list -O /etc/apt/sources.list.d/playonlinux.list
sudo apt-get update
sudo apt-get install playonlinux

[링크 : https://www.playonlinux.com/en/download.html]

 

create virtual device 에서 멈춰있길래 찾아보니 wine이 정작 깔리지 않았다는 사실 발견 -_-

sudo apt-get install wine-stable

[링크 : https://ubuntuforums.org/showthread.php?t=2398938]

 

 

ie 깔아볼려다가 잘 안되서 걍 포기 -_-

'프로그램 사용 > WinE' 카테고리의 다른 글

wine ie  (0) 2019.05.21
wine 한글 폰트  (0) 2019.05.21
odroid XU4 wine 실패? ㅠㅠ  (0) 2018.09.25
한층 더 쩔어진 winE  (0) 2012.04.08
wine 에서 cd넣고 실행시 에러 뜰때  (0) 2012.01.21
Posted by 구차니

화장실로 물이 새서 공사한다고 오가는 신세라.. 힘드네

'개소리 왈왈 > 육아관련 주저리' 카테고리의 다른 글

쏘카 처음 써봄  (4) 2019.05.23
개복이 구름다리 건넘  (2) 2019.05.23
피곤쓰  (2) 2019.04.28
분노쓰  (0) 2019.04.27
피곤  (0) 2019.04.20
Posted by 구차니