TCP/IP transport

Source: Internet
Author: User
Tags sendmsg

Socket Read Stream
protected BufferedReader cin = NULL; Socket Read Stream
Socket send Stream
protected PrintWriter cout;

/*************************************************************************** * Send information to CCB ************************ **************************************************/

public static string Sendmsgjsyh (String msg, String sydwid) throws Fesexception {

String message = "";

Get the service IP String serviceip= "";

Gets the service port int port=0;

try {

Get Service IP Serviceip = fesurlconfig.getfesconfig (). GETITCCBIP ();

serviceip= "172.16.17.24";

Get service Ports port = Fesurlconfig.getfesconfig (). Getitccbport ();

port=8000;

Socketclients sc = new socketclients (SERVICEIP, Port);

Log.error ("CCB Service (IP:" + Serviceip + "ports:" + port);

Message = Sc.sendxmlmsgtojsyhls (Msg.getbytes ());

} catch (Connectexception e) {

Log.error ("CCB Service (IP:" + Serviceip + "PORT:" + port + ") connection failed! "+ e.getmessage ());

throw new Fesexception (e);

} catch (Sockettimeoutexception e) {

Log.error ("CCB Service (IP:" + Serviceip + "PORT:" + port + ") Response timed out! "+ e.getmessage ());

throw new Fesexception (e);

} catch (Exception e) {

Log.error (E.getmessage (), E);

}

return message; }

Method 2:

Public String Sendxmlmsgtojsyhls (byte[] sendmsg) throws Exception {

Establish connection this.startconnect ();

Logger.info ("\nsend message:\n" + new String (sendmsg));

Send Message This.sendbuffer (SENDMSG);

Receive Message byte[] responsemsg = This.recievebufferyh ();

Close connection this.shutdownconnection ();

String Msgres =new string (responsemsg);

return msgres;

}

/**
* @description Send Information
* @author Fei_yfan
* @param bufferstring
* Send Message content
* @throws IOException
*/
public void Sendbuffer (byte[] bufferstring) throws IOException {
Cout.write (New String (bufferstring));
Cout.flush ();
}

Public byte[] Recievebufferyh () throws Exception {
StringBuffer sb = new StringBuffer ();
String s = "";
Reads the contents in bytes from the file, to the end of the file, the Read method returns 1
while ((S=cin.readline ()) = null) {
Sb.append (s+ "\ n");
}
Return sb.tostring (). GetBytes ();
}

TCP/IP transport

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.