C# winsocket连接 Jsonp

     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 AxMSWinsockLib;
namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            
        }


        AxWinsock CK = new AxWinsock();
        private void Form1_Load(object sender, EventArgs e)
        {
            //axWinsock2.Protocol = 0;
            //axWinsock2.LocalPort = 9091;
            //axWinsock2.Close();


            //axWinsock3.Protocol = 0;
            //axWinsock3.LocalPort = 9091;
            //axWinsock3.Close();




            axWinsock1.Protocol = 0;
            axWinsock1.Bind(9091, "127.0.0.1");
            axWinsock1.Close();
            axWinsock1.Listen();


            axWinsock1.ConnectionRequest += axWinsock1_ConnectionRequest;
        }
        int SuoYin = 0;
        public void axWinsock1_ConnectionRequest(object sender, DMSWinsockControlEvents_ConnectionRequestEvent e)
        {
           // axWinsock1.DataArrival += Form1_DataArrival;


            if ((axWinsock2.CtlState != (short)MSWinsockLib.StateConstants.sckConnected) && (axWinsock2.CtlState != (short)MSWinsockLib.StateConstants.sckConnecting) && (axWinsock2.CtlState != (short)MSWinsockLib.StateConstants.sckClosing))
            {
                axWinsock2.Accept(e.requestID);
                //axWinsock2.SendData("天龙八部");
                axWinsock2.DataArrival += Form1_DataArrival;
                //CK = axWinsock2;
            }


            else if ((axWinsock3.CtlState != (short)MSWinsockLib.StateConstants.sckConnected) && (axWinsock3.CtlState != (short)MSWinsockLib.StateConstants.sckConnecting) && (axWinsock3.CtlState != (short)MSWinsockLib.StateConstants.sckClosing))
            {
                axWinsock3.Accept(e.requestID);
                axWinsock3.DataArrival += Form1_DataArrival;
                //CK = axWinsock3;
            }


        }
        public void Form1_DataArrival(object sender, DMSWinsockControlEvents_DataArrivalEvent e)
        {
            string str = null;
            object OT = new object();
            //axWinsock1.GetData(ref str);
            axWinsock2.GetData(ref OT, 8, e.bytesTotal);
            //MessageBox.Show(OT.ToString());
            //object OC = "VoiceAGApi.method.methodCallBack({result: \"0\" ,methodname: \"functionName\"});";
            object OC = "VoiceAGApi.method.methodCallBack({result:\"0\" ,methodname:\"functionName\"});";


            //MessageBox.Show(OC.ToString());
            //getHttpParam = "VoiceAGApi.method.methodCallBack({result:" & Chr(34) & 0 & Chr(34) & ",methodname:" & Chr(34) & functionName & Chr(34) & "});"
            //object OC = "VoiceAGApi.method.methodCallBack{(result:"+Encoding.ASCII.GetBytes("";
            axWinsock2.SendData(OC);


            //CK.GetData(ref OT);
            axWinsock2.SendComplete += Form1_SendComplete;
        }
        public void Form1_SendComplete(object sender, EventArgs e)
        {
            axWinsock2.Close();
        }
        private void axWinsock1_ConnectEvent(object sender, EventArgs e)
        {


        }


        private void axWinsock2_ConnectEvent(object sender, EventArgs e)
        {


        }


        private void sk_ConnectEvent(object sender, EventArgs e)
        {


        }


        private void axWinsock3_ConnectEvent(object sender, EventArgs e)
        {


        }


        private void button1_Click(object sender, EventArgs e)
        {
           byte[] bt=new byte[4];
           bt=Encoding.ASCII.GetBytes("\"");
           int ascii = (short)(bt[0]);


           byte[] array = new byte[1];
           array[0] = (byte)(Convert.ToInt32(34)); //ASCII码强制转换二进制
           string s = Convert.ToString(System.Text.Encoding.ASCII.GetString(array));


           MessageBox.Show(s);






         // string ss=  Convert.ToString(System.Text.Encoding.ASCII.GetString((byte)(Convert.ToInt32(34)));
        }
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值