c#에서 호출한 외부 프로그램과의 소캣 통신 문제

pch2180의 이미지

c#에서 외부 프로그램(파이썬 스크립트)를 실행시키고 쓰레드로 서버를 열어 udp 통신을 하려고 합니다. 파이썬 스크립트가 열어논 포트에 데이터 전송을 하면 c# 프로그램의 쓰레드로 생성한 서버에서 데이터를 받아서 화면에 보여주는 코드를 짰는데, 이상하게 어느정도의 데이터를 보내고나면 더이상 데이터 전송이 안돼네요.. 패킷을 잡아보면 정상적으로 패킷이 전송되다가 어느정도의 데이터를 보내고나면 패킷 자체가 잡히지 않는게 확인됩니다.

이상하게도 아예 외부에서 cmd 창을 직접켜서 파이썬 스크립트를 실행시키면 잘만 패킷이 생성되면서 돌아가던데 c# 프로그램 내부에서 스크립트를 실행시키는 프로세스를 만들면 이런 현상이 발생하네요.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Diagnostics;
 
namespace UdpSocket
{
    public partial class Form1 : Form
    {
        bool used = true;
        Thread t1 = null;
        Process current_pro = null;
        UdpClient srv = null;
 
        public Form1()
        {
            InitializeComponent();
 
            listView1.View = View.Details;
            listView1.FullRowSelect = true;
            listView1.GridLines = true;
            listView1.Columns.Add("Timeline", 800, HorizontalAlignment.Center);
        }
 
        private void udpserverStart()
        {
            try
            {
                srv = new UdpClient(5582);
                IPEndPoint clientEP = new IPEndPoint(IPAddress.Any, 0);
 
                while (used)
                {
                    byte[] dgram = srv.Receive(ref clientEP);
                    listView1.Items.Add(Encoding.Default.GetString(dgram));
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
            finally
            {
 
            }
        }
 
        private void hookStart()
        {
            ProcessStartInfo proInfo = new ProcessStartInfo();
            proInfo.FileName = "python.exe";
            proInfo.Arguments = String.Format("-u {0}", @"output.py");
            proInfo.CreateNoWindow = true;
            proInfo.UseShellExecute = false;
            proInfo.RedirectStandardInput = true;
            proInfo.RedirectStandardOutput = true;
 
            current_pro = new Process();
            current_pro.StartInfo = proInfo;
            current_pro.Start();
            current_pro.Exited += (sender, e) =>
            {
                MessageBox.Show("Hook Process exited!");
            };
 
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            t1 = new Thread(udpserverStart);
            t1.Start();
            hookStart();
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            used = false;
            srv.Close();
            //t1.Join();
            t1.Abort();
            current_pro.Kill();
            this.Close();
        }
 
 
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
 
        }
    }
}

다음은 python 스크립트입니다.

sc = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sc.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 100000)
 
def message(message, data):
    if message['type'] == 'send':
        try:
            payload = str(message['payload']) + '\n'
            sc.sendto(payload.encode(), ('127.0.0.1', 5582))
            print(str(message['payload']) + '\n')
        except:
            print('error');
    elif message['type'] == 'error':
        try:
            print(str(message['stack']) + '\n')
        except:
            print('error');
    else:
        print("something...")

받는 쪽은 문제가 없어 보이는데 보내는 쪽에서 전송이 안됩니다..
파이썬 스크립트가 문제인거 같은데 또 c# 프로그램에서가 아닌 아예 외부에서 실행시키면 잘만 돌아가고...
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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.